/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var http = CreateRequestObject();

function CreateRequestObject()
{
    var req;
    if (window.XMLHttpRequest)
    {
        //For FireFox, Safari, Opera
        req = new XMLHttpRequest();
    } 
    else
    {
        if(window.ActiveXObject)
        {
            //For IE 5+
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
            alert("Your brower is not IE 5 or higher, or FireFox or Safari or Opera");
    }
    return req;
}
/*Hàm này thay đổi nội dung của div được chỉ định bằng ajax
 *tham số : method (get,post) ; url (địa chỉ controller) ; divID (id của div có nội dung cần thay đổi)
 */
function AjaxNoiDung(method, url, divID)
{
    if (method == 'get' || method == 'post' || method == 'GET' || method == 'POST')
    {
        http.open(method, url , true);
        http.onreadystatechange = function()
        {
            if (http.readyState == 4 && http.status == 200)
            {
                var response = http.responseText;

                if (response !="")
                {
                    document.getElementById(divID).innerHTML = response;
                }
            }
        }
        http.send(null);
    }
}
/*Hàm này nhận về thông báo từ controller được chỉ định và hiển thị cho user
 *tham số : url (địa chỉ controller)
 *trả về : false nhằm ngăn cản sự kiện submit
 */
function AjaxThongBao(url)
{
    var method = "POST";
    if (method == 'get' || method == 'post' || method == 'GET' || method == 'POST')
    {
        http.open(method, url , true);
        http.onreadystatechange = function()
        {
            if (http.readyState == 4 && http.status == 200)
            {
                var response = http.responseText;
                if (response !="")
                {
                    document.getElementById('msgerr').innerHTML = response;
                    var msg = response;
                    MSG(msg);
                    return false;
                }
            }
            return true;
        }
        http.send(null);
    }
}
/* Hàm kiểm tra thông tin login có rỗng hoặc chứa các ký tự lạ */
function CheckLogin()
{
    var us = document.loginform.user.value;
    var pw = document.loginform.pass.value;
    if(us.indexOf("'") != -1 || us.indexOf("\"") != -1 || us.indexOf("&") != -1 || us.length ==0)
        return false;
    if(pw.indexOf("'") != -1 || pw.indexOf("\"") != -1 || pw.indexOf("&") != -1 || pw.length ==0)
        return false;
    return true;
}

// Start: Xử lý khu vực


function NewArea(item, rightmsg) { // Vào trang quản lý khu vực
    var a = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=1";
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../KhuVuc_Controller?action=Show&item="+item;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CreateArea(msg, rightmsg, msgchecksubmit) {  // Tạo khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=2";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var areaname = document.addArea.areaname.value;
                if(areaname == ""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../KhuVuc_Controller?action=Add&areaname="+areaname;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "areaexist"){
                                MSG(msg);
                            }
                            else{ // Nếu tạo thành công, hiển thị lại danh sách khu vực ở bảng bên phải
                                var aa = "../KhuVuc_Controller?action=ShowKVTao&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSKV").html(result);
                                    }
                                });
                                $("#arealang").html(result); // show chi tiết khu vực ở bảng bên trái
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Edit_tenkv(mann, tenkv) { // chuyển sang textbox để update
    var x = "#tenkv_"+mann;
    $(x).parent().html("<input type='textbox' class='text' style='width:110px' id="+x+" value='"+tenkv+"'>");
}
function Edit_soghe(maban, soghe) { // chuyển sang textbox để update
    $("#soghe").parent().html("<input type='textbox' class='text' name='soghe' style='width:40px' maxlength='3' onkeypress='return keypress(event)' id="+maban+" value='"+soghe+"'>");
}
function Save_edit( makv, mann, rightmsg) {    // Update tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=3";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "#tenkv_"+mann;
                var z = document.getElementById(x);
                var tenkv = z.value;
                var m = document.getElementById("areaexist");
                var msg = m.value;
                var a = "../KhuVuc_Controller?action=Edit&tenkv="+tenkv+"&makv="+makv+"&mann="+mann;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        if(result == "areaexist"){
                            MSG(msg);
                        }
                        else{
                            $("#arealang").html(result);
                            var aa = "../KhuVuc_Controller?action=ShowKV&item=1";  // hiển thị lại danh sách khu vực ở bảng bên phải
                            $.ajax({
                                url:aa,
                                dataType:"html",
                                success:function(result){
                                    $("#DSKV").html(result);
                                }
                            });
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Save_soghe( maban, rightmsg) {    // Update so ghe
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=3";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
//                var x = "#area #"+maban;
//                var soghe = $(x).val();
                var soghe = document.detailtable.soghe.value;
                
                var a = "../Ban_Controller?action=EditSoGhe&maban="+maban+"&soghe="+soghe;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DetailTable").html(result);
                        var aa = "../Ban_Controller?action=ShowBan&item=1";
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#DSBan").html(result);
                            }
                        });
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
    
}
function UpdateStatusKV(status,  makv, rightmsg ){  // update tình trạng khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=3";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuVuc_Controller?action=UpdateStatusKV&makv="+makv+"&status="+status+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSKV").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateKVBan(makv, maban, rightmsg ){  // update tình trạng khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=3";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../Ban_Controller?action=UpdateKVBan&makv="+makv+"&maban="+maban+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowLangKV(makv, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=1";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuVuc_Controller?action=ShowLangKV&makv="+makv;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#arealang").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchKV(item, rightmsg){ //Search khu vuc
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=1";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchTenKV input').val();
                var status = $('#searchTenKV select').val();
                var a = "../KhuVuc_Controller?action=SearchKV&status="+status+"&tenkv="+tenkv+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSKV").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenKV(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=1";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenkv";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuVuc_Controller?action=SortTenKV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuVuc_Controller?action=SortTenKV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTKV( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=1";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ttkv";
                if(sort == 'down'){
                    $('#titledskv2 div.down2').removeClass('down2');
                    $('#titledskv2 #sortkv2').addClass('up2');
                    var order1 = "asc";
                    var a = "../KhuVuc_Controller?action=SortTTKV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up2').removeClass('up2');
                    $('#titledskv2 #sortkv2').addClass('down2');
                    var order2 = "desc";
                    var aa = "../KhuVuc_Controller?action=SortTTKV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenKV( sort, item, rightmsg){ //Sort tên khu vực kết quả tìm kiếm
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=1";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchTenKV input').val();
                var status = $('#searchTenKV select').val();
                var sortkv = 'tenkv';
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var aa = "../KhuVuc_Controller?action=SortSearchTenKV&item="+item+"&order="+order1+"&status="+status+"&tenkv="+tenkv+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aaa = "../KhuVuc_Controller?action=SortSearchTenKV&item="+item+"&order="+order2+"&status="+status+"&tenkv="+tenkv+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTKV( sort, item, rightmsg){     // Sort tinh trạng khu vực kết quả tìm kiếm
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=1";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchTenKV input').val();
                var status = $('#searchTenKV select').val();
                var sortkv = 'tenkv';
                if(sort == 'down'){
                    $('#titledskv2 div.down2').removeClass('down2');
                    $('#titledskv2 #sortkv2').addClass('up2');
                    var order1 = "asc";
                    var aa = "../KhuVuc_Controller?action=SortSearchTTKV&item="+item+"&order="+order1+"&status="+status+"&tenkv="+tenkv+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up2').removeClass('up2');
                    $('#titledskv2 #sortkv2').addClass('down2');
                    var order2 = "desc";
                    var aaa = "../KhuVuc_Controller?action=SortSearchTTKV&item="+item+"&order="+order2+"&status="+status+"&tenkv="+tenkv+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });

   
}

// End : Xử lý khu vực

/// *************************************************************************************

// Start : Xử lý bàn

function NewTable(item, rightmsg) { // Hiển thị trang quản lý bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../Ban_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);    
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CreateTable(rightmsg, msgchecksubmit) { // Tạo bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=5";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var makv = document.addTable.tenkv.value;
                var ban = document.addTable.ban.value;
                var ghe = document.addTable.ghe.value;
                if(makv == "" || ban == "" || ghe == ""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../Ban_Controller?action=Add&makv="+makv+"&ban="+ban+"&ghe="+ghe;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            var aa = "../Ban_Controller?action=ShowBan&item=1";
                            $.ajax({
                                url:aa,
                                dataType:"html",
                                success:function(result){
                                    $("#DSBan").html(result);
                                    var aaa = "../Ban_Controller?action=Map&makv="+makv+"&item=1";
                                    $.ajax({
                                        url:aaa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#Map").html(result);
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
                
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowMap(makv, item, rightmsg){   
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../Ban_Controller?action=Map&makv="+makv+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#Map").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateStatusBan(status,  maban, rightmsg, tinhtrang, servicemsg ){ // Cập nhật tình trạng bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=6";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                if(tinhtrang != "1" && status == "0"){
                    MSG(servicemsg);
                }
                else{
                    var a = "../Ban_Controller?action=UpdateStatusBan&maban="+maban+"&status="+status+"&item=1";
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSBan").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchBan( item, rightmsg){ // Search bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchTenKV .tenkv').val();
                var tenban = $('#searchTenKV .tenban').val();
                var soghe = $('#searchTenKV .soghe').val();
                var status = $('#searchTenKV select').val();
                var a = "../Ban_Controller?action=SearchBan&tenban="+tenban+"&tenkv="+tenkv+"&item="+item+"&status="+status+"&soghe="+soghe;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSBan").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function BanSortTenKV(sort, item, rightmsg){ // Sort tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenkv";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../Ban_Controller?action=SortTenKV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSBan").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../Ban_Controller?action=SortTenKV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSBan").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function BanSortTTKV( sort, item, rightmsg){ // Sort tình trạng bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ttkv";
                if(sort == 'down'){
                    $('#titledskv2 div.down2').removeClass('down2');
                    $('#titledskv2 #sortkv2').addClass('up2');
                    var order1 = "asc";
                    var a = "../Ban_Controller?action=SortTTKV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){

                            $("#DSBan").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up2').removeClass('up2');
                    $('#titledskv2 #sortkv2').addClass('down2');
                    var order2 = "desc";
                    var aa = "../Ban_Controller?action=SortTTKV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){

                            $("#DSBan").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function BanSortSearchTenKV( sort, item, rightmsg){ // Sort tên khu vực kết quả search
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchTenKV .tenkv').val();
                var tenban = $('#searchTenKV .tenban').val();
                var status = $('#searchTenKV select').val();
                var soghe = $('#searchTenKV .soghe').val();
                var sortkv = 'tenkv';
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var aa = "../Ban_Controller?action=SortSearchTenKV&item="+item+"&order="+order1+"&status="+status+"&tenkv="+tenkv+"&tenban="+tenban+"&sort="+sort+"&sortkv="+sortkv+"&soghe="+soghe;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSBan").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aaa = "../Ban_Controller?action=SortSearchTenKV&item="+item+"&order="+order2+"&status="+status+"&tenkv="+tenkv+"&tenban="+tenban+"&sort="+sort+"&sortkv="+sortkv+"&soghe="+soghe;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){
                            $("#DSBan").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function BanSortSearchTTKV( sort, item, rightmsg){   // Sort tình trạng bàn kết quả search
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchTenKV .tenkv').val();
                var tenban = $('#searchTenKV .tenban').val();
                var status = $('#searchTenKV select').val();
                var soghe = $('#searchTenKV .soghe').val();
                var sortkv = 'ttkv';
                if(sort == 'down'){
                    $('#titledskv2 div.down2').removeClass('down2');
                    $('#titledskv2 #sortkv2').addClass('up2');
                    var order1 = "asc";
                    var aa = "../Ban_Controller?action=SortSearchTTKV&item="+item+"&order="+order1+"&status="+status+"&tenkv="+tenkv+"&tenban="+tenban+"&sort="+sort+"&sortkv="+sortkv+"&soghe="+soghe;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSBan").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up2').removeClass('up2');
                    $('#titledskv2 #sortkv2').addClass('down2');
                    var order2 = "desc";
                    var aaa = "../Ban_Controller?action=SortSearchTTKV&item="+item+"&order="+order2+"&status="+status+"&tenkv="+tenkv+"&tenban="+tenban+"&sort="+sort+"&sortkv="+sortkv+"&soghe="+soghe;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){
                            $("#DSBan").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function DetailTable(maban, rightmsg){    // Show detail bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=4";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../Ban_Controller?action=DetailTable&maban="+maban;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DetailTable").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });   
}
function UpdateTTBan(mattban, maban, makv, rightmsg){  // Update trạng thái bàn: đã tính tiền, đang dọn, ...
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=6";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../Ban_Controller?action=UpdateTTBan&mattban="+mattban+"&maban="+maban;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        var aa = "../Ban_Controller?action=Map&makv="+makv+"&item=1";
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#Map").html(result);
                            }
                        });
                        $("#DetailTable").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
    
}

// End : Xử lý bàn

// Start: Nhật ký hệ thống

function History(item, rightmsg) { // Show trang nhật ký
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhatKyHT_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchNhatKy(item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchNK .tungay').val();
                var tugio = $('#searchNK .tugio').val();
                var tuphut = $('#searchNK .tuphut').val();
                var denngay = $('#searchNK .denngay').val();
                var dengio = $('#searchNK .dengio').val();
                var denphut = $('#searchNK .denphut').val();
                var nhanvien = $('#searchNK .nhanvien').val();
                var thaotac = $('#searchNK .thaotac').val();
                var doituong = $('#searchNK .doituong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var a = "../NhatKyHT_Controller?action=SearchNhatKy&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&item="+item;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSNK").html(result);
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
                
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayGioNK( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhatKyHT_Controller?action=SortNgayGio&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhatKyHT_Controller?action=SortNgayGio&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });

}
function SortNhanVienNK( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "nhanvien";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhatKyHT_Controller?action=SortNhanVien&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhatKyHT_Controller?action=SortNhanVien&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortThaoTacNK(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "thaotac";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhatKyHT_Controller?action=SortThaoTacNK&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhatKyHT_Controller?action=SortThaoTacNK&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortDoiTuongNK( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "doituong";
                if(sort == 'down'){
                    $('#titledskv4 div.down2').removeClass('down2');
                    $('#titledskv4 #sortkv4').addClass('up2');
                    var order1 = "asc";
                    var a = "../NhatKyHT_Controller?action=SortDoiTuongNK&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up2').removeClass('up2');
                    $('#titledskv4 #sortkv4').addClass('down2');
                    var order2 = "desc";
                    var aa = "../NhatKyHT_Controller?action=SortDoiTuongNK&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayGioNK( sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchNK .tungay').val();
                var tugio = $('#searchNK .tugio').val();
                var tuphut = $('#searchNK .tuphut').val();
                var denngay = $('#searchNK .denngay').val();
                var dengio = $('#searchNK .dengio').val();
                var denphut = $('#searchNK .denphut').val();
                var nhanvien = $('#searchNK .nhanvien').val();
                var thaotac = $('#searchNK .thaotac').val();
                var doituong = $('#searchNK .doituong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = 'ngaygio';
                                if(sort == 'down'){
                                    $('#titledskv1 div.down1').removeClass('down1');
                                    $('#titledskv1 #sortkv1').addClass('up1');
                                    var order1 = "asc";
                                    var aa = "../NhatKyHT_Controller?action=SortSearchNgayGioNK&item="+item+"&order="+order1+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv1 div.up1').removeClass('up1');
                                    $('#titledskv1 #sortkv1').addClass('down1');
                                    var order2 = "desc";
                                    var aaa = "../NhatKyHT_Controller?action=SortSearchNgayGioNK&item="+item+"&order="+order2+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aaa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNhanVienNK( sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchNK .tungay').val();
                var tugio = $('#searchNK .tugio').val();
                var tuphut = $('#searchNK .tuphut').val();
                var denngay = $('#searchNK .denngay').val();
                var dengio = $('#searchNK .dengio').val();
                var denphut = $('#searchNK .denphut').val();
                var nhanvien = $('#searchNK .nhanvien').val();
                var thaotac = $('#searchNK .thaotac').val();
                var doituong = $('#searchNK .doituong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){                                
                                var sortkv = 'nhanvien';
                                if(sort == 'down'){
                                    $('#titledskv2 div.down1').removeClass('down1');
                                    $('#titledskv2 #sortkv2').addClass('up1');
                                    var order1 = "asc";
                                    var aa = "../NhatKyHT_Controller?action=SortSearchNhanVienNK&item="+item+"&order="+order1+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv2 div.up1').removeClass('up1');
                                    $('#titledskv2 #sortkv2').addClass('down1');
                                    var order2 = "desc";
                                    var aaa = "../NhatKyHT_Controller?action=SortSearchNhanVienNK&item="+item+"&order="+order2+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aaa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchThaoTacNK( sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchNK .tungay').val();
                var tugio = $('#searchNK .tugio').val();
                var tuphut = $('#searchNK .tuphut').val();
                var denngay = $('#searchNK .denngay').val();
                var dengio = $('#searchNK .dengio').val();
                var denphut = $('#searchNK .denphut').val();
                var nhanvien = $('#searchNK .nhanvien').val();
                var thaotac = $('#searchNK .thaotac').val();
                var doituong = $('#searchNK .doituong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){                                
                                var sortkv = 'thaotac';
                                if(sort == 'down'){
                                    $('#titledskv3 div.down1').removeClass('down1');
                                    $('#titledskv3 #sortkv3').addClass('up1');
                                    var order1 = "asc";
                                    var aa = "../NhatKyHT_Controller?action=SortSearchThaoTacNK&item="+item+"&order="+order1+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv3 div.up1').removeClass('up1');
                                    $('#titledskv3 #sortkv3').addClass('down1');
                                    var order2 = "desc";
                                    var aaa = "../NhatKyHT_Controller?action=SortSearchThaoTacNK&item="+item+"&order="+order2+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aaa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchDoiTuongNK( sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchNK .tungay').val();
                var tugio = $('#searchNK .tugio').val();
                var tuphut = $('#searchNK .tuphut').val();
                var denngay = $('#searchNK .denngay').val();
                var dengio = $('#searchNK .dengio').val();
                var denphut = $('#searchNK .denphut').val();
                var nhanvien = $('#searchNK .nhanvien').val();
                var thaotac = $('#searchNK .thaotac').val();
                var doituong = $('#searchNK .doituong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){                            
                                var sortkv = 'doituong';
                                if(sort == 'down'){
                                    $('#titledskv4 div.down4').removeClass('down2');
                                    $('#titledskv4 #sortkv4').addClass('up2');
                                    var order1 = "asc";
                                    var aa = "../NhatKyHT_Controller?action=SortSearchDoiTuongNK&item="+item+"&order="+order1+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv4 div.up2').removeClass('up2');
                                    $('#titledskv4 #sortkv4').addClass('down2');
                                    var order2 = "desc";
                                    var aaa = "../NhatKyHT_Controller?action=SortSearchDoiTuongNK&item="+item+"&order="+order2+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&nhanvien="+nhanvien+"&thaotac="+thaotac+"&doituong="+doituong+"&sort="+sort+"&sortkv="+sortkv;
                                    $.ajax({
                                        url:aaa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNK").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CheckAllKV(){
    x = document.dsnk.total.value;
    if(x > 1){
        optionKV = document.dsnk.optionKV;
        for(i=0; i<optionKV.length; i++)
        {
            if(!optionKV[i].checked){
                optionKV[i].click();
            }
        }
    }
    else{
        $('.optionKV').click();
    }
}
function CheckAllNT(){    
    chknt = document.AddDetailProDay.chknt;
    for(i=0; i<chknt.length; i++)
    {
        if(!chknt[i].checked){
            chknt[i].click();
        }
    }
}
function DeleteKV( item, rightmsg){
    
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=8";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "";
                total = document.dsnk.total.value;
                if(total > 1){
                    optionKV = document.dsnk.optionKV;
                    for(i = 0; i < optionKV.length; i++)
                    {
                        if(optionKV[i].checked)
                        {
                            x =   x  + optionKV[i].value + "-" ;
                        }
                    }
                }
                else{
                    if(document.dsnk.optionKV.checked){
                        x = document.dsnk.optionKV.value;
                    }
                }
                if(x == "") return;
                else{                    
                    var a = "../NhatKyHT_Controller?action=DeleteKV&makv="+x+"&item="+item;                    
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNK").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}

// End : Nhật ký hệ thống


// Start : Nhân viên

function User( item, rightmsg){ 
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhanVien_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });    
}
function CreateUser(rightmsg, msgchecksubmit){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=13";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tennv = document.createuser.tennv.value;
                var username = document.createuser.username.value;
                var nnv = document.createuser.nnv.value;
                var diachi = document.createuser.diachi.value;
                var sodt = document.createuser.sodt.value;
                var ngayvaolam = document.createuser.ngayvaolam.value;
                if(tennv =="" || username =="" || nnv =="" || diachi =="" || sodt =="" || ngayvaolam==""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../NhanVien_Controller?action=CreateUser&tennv="+tennv+"&username="+username+"&nnv="+nnv+"&diachi="+diachi+"&sodt="+sodt+"&ngayvaolam="+ngayvaolam;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "success"){
                                var aa = "../NhanVien_Controller?action=ShowDSNV&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSNV").html(result);
                                    }
                                });
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateNNV(mannv,  manv, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=10";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhanVien_Controller?action=UpdateNNV&mannv="+mannv+"&manv="+manv+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSNV").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });    
}
function UpdateStatusNV(status,  manv, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=10";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhanVien_Controller?action=UpdateStatusNV&status="+status+"&manv="+manv+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSNV").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });    
}
function SortHoTenNV(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tennv";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhanVien_Controller?action=SortHoTenNV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhanVien_Controller?action=SortHoTenNV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayVaoLam(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngayvaolam";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhanVien_Controller?action=SortNgayVaoLam&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhanVien_Controller?action=SortNgayVaoLam&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNhomNV(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "nhomnv";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhanVien_Controller?action=SortNhomNV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhanVien_Controller?action=SortNhomNV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTNV(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ttnv";
                if(sort == 'down'){
                    $('#titledskv4 div.down2').removeClass('down2');
                    $('#titledskv4 #sortkv4').addClass('up2');
                    var order1 = "asc";
                    var a = "../NhanVien_Controller?action=SortTTNV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up2').removeClass('up2');
                    $('#titledskv4 #sortkv4').addClass('down2');
                    var order2 = "desc";
                    var aa = "../NhanVien_Controller?action=SortTTNV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchUser( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var HOTEN = $('#searchNV .HOTEN').val();
                var NGAYVAOLAM = $('#searchNV .NGAYVAOLAM').val();
                var NHOMNHANVIEN = $('#searchNV .selectNHOMNHANVIEN').val();
                var TINHTRANG = $('#searchNV .selectTINHTRANG').val();
                var a = "../NhanVien_Controller?action=SearchUser&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSNV").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchHoTenNV( item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var HOTEN = $('#searchNV .HOTEN').val();
                var NGAYVAOLAM = $('#searchNV .NGAYVAOLAM').val();
                var NHOMNHANVIEN = $('#searchNV .selectNHOMNHANVIEN').val();
                var TINHTRANG = $('#searchNV .selectTINHTRANG').val();
                var sortkv = 'tennv';
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var aa = "../NhanVien_Controller?action=SortSearchHoTenNV&item="+item+"&order="+order1+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){

                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aaa = "../NhanVien_Controller?action=SortSearchHoTenNV&item="+item+"&order="+order2+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){

                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayVaoLam( item, sort,rightmsg  ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var HOTEN = $('#searchNV .HOTEN').val();
                var NGAYVAOLAM = $('#searchNV .NGAYVAOLAM').val();
                var NHOMNHANVIEN = $('#searchNV .selectNHOMNHANVIEN').val();
                var TINHTRANG = $('#searchNV .selectTINHTRANG').val();
                var sortkv = 'ngayvaolam';
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var aa = "../NhanVien_Controller?action=SortSearchNgayVaoLam&&item="+item+"&order="+order1+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aaa = "../NhanVien_Controller?action=SortSearchNgayVaoLam&item="+item+"&order="+order2+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNhomNV(item, sort, rightmsg ){ 
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var HOTEN = $('#searchNV .HOTEN').val();
                var NGAYVAOLAM = $('#searchNV .NGAYVAOLAM').val();
                var NHOMNHANVIEN = $('#searchNV .selectNHOMNHANVIEN').val();
                var TINHTRANG = $('#searchNV .selectTINHTRANG').val();
                var sortkv = 'nhomnv';
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var aa = "../NhanVien_Controller?action=SortSearchNhomNV&item="+item+"&order="+order1+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){                            
                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aaa = "../NhanVien_Controller?action=SortSearchNhomNV&item="+item+"&order="+order2+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTNV( item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=9";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var HOTEN = $('#searchNV .HOTEN').val();
                var NGAYVAOLAM = $('#searchNV .NGAYVAOLAM').val();
                var NHOMNHANVIEN = $('#searchNV .selectNHOMNHANVIEN').val();
                var TINHTRANG = $('#searchNV .selectTINHTRANG').val();
                var sortkv = 'ttnv';
                if(sort == 'down'){
                    $('#titledskv4 div.down2').removeClass('down2');
                    $('#titledskv4 #sortkv4').addClass('up2');
                    var order1 = "asc";
                    var aa = "../NhanVien_Controller?action=SortSearchTTNV&item="+item+"&order="+order1+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up2').removeClass('up2');
                    $('#titledskv4 #sortkv4').addClass('down2');
                    var order2 = "desc";
                    var aaa = "../NhanVien_Controller?action=SortSearchTTNV&item="+item+"&order="+order2+"&HOTEN="+HOTEN+"&NGAYVAOLAM="+NGAYVAOLAM+"&NHOMNHANVIEN="+NHOMNHANVIEN+"&TINHTRANG="+TINHTRANG+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aaa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateDetail( manv, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=10";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhanVien_Controller?action=Detail&manv="+manv;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#ShowTaoNV").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function PhanQuyenCaNhan( manv, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=12";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../NhanVien_Controller?action=PhanQuyenCaNhan&manv="+manv;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){

                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });  
}
function PhanQuyenNhom(rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=11";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../NhanVien_Controller?action=PhanQuyenNhom";
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });

  
}


function UpdateQuyenCaNhan(manv, msg, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=12";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var chkquyen = document.phanquyen.chkquyen;
                var x = "";
                var y = "";
                for(i = 0; i < chkquyen.length; i++)
                {
                    if(chkquyen[i].checked)
                    {
                        x =   x  + chkquyen[i].value + "-" ;
                    }
                    else{
                        y =   y  + chkquyen[i].value + "-" ;
                    }
                }
                var a = "../NhanVien_Controller?action=UpdateQuyenCaNhan&manv="+manv+"&yes="+x+"&no="+y;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        if(result == "success"){
                            MSG(msg);
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateQuyenNhom(msg, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=11";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var chkquyen = document.phanquyen.chkquyen;
                var x = "";
                var n = "";
                var y = "";
                var m = "";
                for(i = 0; i < chkquyen.length; i++)
                {
                    if(chkquyen[i].checked)
                    {
                        x =   x  + chkquyen[i].value + "-" ;
                        n =   n  + chkquyen[i].className + "-";
                    }
                    else{
                        y =   y  + chkquyen[i].value + "-" ;
                        m =   m  + chkquyen[i].className + "-";
                    }
                }
                var a = "../NhanVien_Controller?action=UpdateQuyenNhom&yes="+x+"&no="+y+"&mayes="+n+"&mano="+m;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        if(result == "success"){
                            MSG(msg);
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateDetailNV(manv,  msg, rightmsg, msgchecksubmit){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=10";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tennv = document.createuser.tennv.value;
                var diachi = document.createuser.diachi.value;
                var sodt = document.createuser.sodt.value;
                var ngayvaolam = document.createuser.ngayvaolam.value;
                if(tennv =="" || diachi =="" || sodt =="" || ngayvaolam==""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../NhanVien_Controller?action=UpdateDetailNV&tennv="+tennv+"&diachi="+diachi+"&sodt="+sodt+"&ngayvaolam="+ngayvaolam+"&manv="+manv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "success"){
                                var aa = "../NhanVien_Controller?action=ShowDSNV&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSNV").html(result);
                                    }
                                });
                                MSG(msg);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End : Nhân viên

// Start: Nhóm món ăn
 
function Foodgroups( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhomMA_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });    
}
function AddFoodGroup(msgnma, rightmsg, msgchecksubmit){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=16";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var maloaima = document.addFoodGroup.maloaima.value;
                var nhomma = document.addFoodGroup.nhomma.value;
                if(nhomma == ""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var b = "../NhomMA_Controller?action=CheckTenNMA&nhomma="+nhomma;
                    $.ajax({
                        url:b,
                        dataType:"html",
                        success:function(result){
                            if(result == "exist"){
                                MSG(msgnma);
                            }
                            else{
                                var a = "../NhomMA_Controller?action=Add&maloaima="+maloaima+"&nhomma="+nhomma;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        var aa = "../NhomMA_Controller?action=ShowNhomMA&item=1";
                                        $.ajax({
                                            url:aa,
                                            dataType:"html",
                                            success:function(result){
                                                $("#DSNMA").html(result);
                                            }
                                        });
                                        $("#foodgrouplang").html(result);
                                    }
                                });
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowLangFG(MaNMA, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhomMA_Controller?action=ShowLangFG&MaNMA="+MaNMA;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#foodgrouplang").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });    
}
function Edit_tenNMA(mann, tennma) { // chuyển sang textbox để update
    var x = "#tenkv_"+mann;
    $(x).parent().html("<input type='textbox' class = 'text' style='width:120px' id="+x+" value='"+tennma+"'>");
}
function Save_editNMA( manma, mann, rightmsg) {    // Update tên khu vực
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=15";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "#tenkv_"+mann;
                var z = document.getElementById(x);
                var tennma = z.value;
                var b = "../NhomMA_Controller?action=CheckTenNMAEdit&nhomma="+tennma+"&manma="+manma;
                var m = document.getElementById("foodgroupexist");
                var msg = m.value;
                $.ajax({
                    url:b,
                    dataType:"html",
                    success:function(result){
                        if(result == "exist"){
                            MSG(msg);
                        }
                        else{
                            var a = "../NhomMA_Controller?action=Edit&tennma="+tennma+"&manma="+manma+"&mann="+mann;
                            $.ajax({
                                url:a,
                                dataType:"html",
                                success:function(result){
                                    $("#foodgrouplang").html(result);
                                    var aa = "../NhomMA_Controller?action=ShowNhomMA&item=1";
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSNMA").html(result);
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateStatusNMA(status,  manma, rightmsg ){  // update tình trạng khu vực
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=15";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhomMA_Controller?action=UpdateStatusNMA&manma="+manma+"&status="+status+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSNMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
    
}
function UpdateLMA(manma,  malma, rightmsg ){  // update tình trạng khu vực
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=15";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../NhomMA_Controller?action=UpdateLMA&manma="+manma+"&malma="+malma+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSNMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });

}
function SearchNMA(item, rightmsg){ //Search khu vuc
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var loaithucan = $('#searchNMA .loaithucan').val();
                var tennhommonan = $('#searchNMA .tennhommonan').val();
                var status = $('#searchNMA select').val();
                var a = "../NhomMA_Controller?action=Search&status="+status+"&tennhommonan="+tennhommonan+"&loaithucan="+loaithucan+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSNMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });    
}
function SortTenLMA(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenlma";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhomMA_Controller?action=SortTenLMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhomMA_Controller?action=SortTenLMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenNMAA(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tennma";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhomMA_Controller?action=SortTenNMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhomMA_Controller?action=SortTenNMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTNMA(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ttnma";
                if(sort == 'down'){
                    $('#titledskv3 div.down2').removeClass('down2');
                    $('#titledskv3 #sortkv3').addClass('up2');
                    var order1 = "asc";
                    var a = "../NhomMA_Controller?action=SortTTNMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up2').removeClass('up2');
                    $('#titledskv3 #sortkv3').addClass('down2');
                    var order2 = "desc";
                    var aa = "../NhomMA_Controller?action=SortTTNMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenLMA(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var loaithucan = $('#searchNMA .loaithucan').val();
                var tennhommonan = $('#searchNMA .tennhommonan').val();
                var status = $('#searchNMA select').val();
                var sortkv = "tenlma";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhomMA_Controller?action=SortSearchTenLMA&status="+status+"&tennhommonan="+tennhommonan+"&loaithucan="+loaithucan+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhomMA_Controller?action=SortSearchTenLMA&status="+status+"&tennhommonan="+tennhommonan+"&loaithucan="+loaithucan+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenNMAA(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var loaithucan = $('#searchNMA .loaithucan').val();
                var tennhommonan = $('#searchNMA .tennhommonan').val();
                var status = $('#searchNMA select').val();
                var sortkv = "tennma";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../NhomMA_Controller?action=SortSearchTenNMA&status="+status+"&tennhommonan="+tennhommonan+"&loaithucan="+loaithucan+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../NhomMA_Controller?action=SortSearchTenNMA&status="+status+"&tennhommonan="+tennhommonan+"&loaithucan="+loaithucan+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTNMA(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=14";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var loaithucan = $('#searchNMA .loaithucan').val();
                var tennhommonan = $('#searchNMA .tennhommonan').val();
                var status = $('#searchNMA select').val();
                var sortkv = "ttnma";
                if(sort == 'down'){
                    $('#titledskv3 div.down2').removeClass('down2');
                    $('#titledskv3 #sortkv3').addClass('up2');
                    var order1 = "asc";
                    var a = "../NhomMA_Controller?action=SortSearchTTNMA&status="+status+"&tennhommonan="+tennhommonan+"&loaithucan="+loaithucan+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up2').removeClass('up2');
                    $('#titledskv3 #sortkv3').addClass('down2');
                    var order2 = "desc";
                    var aa = "../NhomMA_Controller?action=SortSearchTTNMA&status="+status+"&tennhommonan="+tennhommonan+"&loaithucan="+loaithucan+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSNMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}

// End: Nhóm món ăn

// Start: Đơn vị tính
function Unit( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=17";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../DVTinh_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
} 
function CreateDVT(msg, rightmsg, msgchecksubmit) {  // Tạo khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=18";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var dvtname = document.addDVT.dvtname.value;
                if(dvtname == ""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../DVTinh_Controller?action=Add&dvtname="+dvtname;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "exist"){
                                MSG(msg);
                            }
                            else{ // Nếu tạo thành công, hiển thị lại danh sách khu vực ở bảng bên phải
                                var aa = "../DVTinh_Controller?action=ShowDVT&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSDVT").html(result);
                                    }
                                });
                                $("#dvtlang").html(result); // show chi tiết khu vực ở bảng bên trái
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowLangDVT(madvt, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=17";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../DVTinh_Controller?action=ShowLangDVT&madvt="+madvt;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#dvtlang").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });  
}
function Edit_tendvt(mann, tendvt) { // chuyển sang textbox để update
    var x = "#tenkv_"+mann;
    $(x).parent().html("<input type='textbox' class = 'text' style='width:100px' id="+x+" value='"+tendvt+"'>");
}
function Save_editdvt( madvt, mann, rightmsg) {    // Update tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=19";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "#tenkv_"+mann;
                var z = document.getElementById(x);
                var tendvt = z.value;
                var m = document.getElementById("unitexist");
                var msg = m.value;
                var a = "../DVTinh_Controller?action=Edit&tendvt="+tendvt+"&madvt="+madvt+"&mann="+mann;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        if(result == "exist"){
                            MSG(msg);
                        }
                        else{
                            $("#dvtlang").html(result);
                            var aa = "../DVTinh_Controller?action=ShowDVT&item=1";  // hiển thị lại danh sách khu vực ở bảng bên phải
                            $.ajax({
                                url:aa,
                                dataType:"html",
                                success:function(result){
                                    $("#DSDVT").html(result);
                                }
                            });
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenDVT(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=17";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tendvt";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../DVTinh_Controller?action=SortTenDVT&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDVT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DVTinh_Controller?action=SortTenDVT&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDVT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    }); 
}
function SearchDVT(item, rightmsg){ //Search khu vuc
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=17";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tendvt = $('#searchDVT input').val();
                var a = "../DVTinh_Controller?action=Search&tendvt="+tendvt+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSDVT").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenDVT(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=17";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tendvt = $('#searchDVT input').val();
                var sortkv = "tendvt";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../DVTinh_Controller?action=SortSearchTenDVT&tendvt="+tendvt+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){

                            $("#DSDVT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DVTinh_Controller?action=SortSearchTenDVT&tendvt="+tendvt+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDVT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End: Đơn vị tính

// Start: Tiền tệ
function Currency( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../TienTe_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CreateCurrency(msg, rightmsg, msgchecksubmit) {  // Tạo khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=21";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var currencycode = document.addCurrency.currencycode.value;
                var currencyname = document.addCurrency.currencyname.value;
                var symbols = document.addCurrency.symbols.value;
                if(currencyname == "" || symbols == ""  ){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../TienTe_Controller?action=Add&currencycode="+currencycode+"&currencyname="+currencyname+"&symbols="+symbols;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){

                            if(result == "currencyexist"){
                                MSG(msg);
                            }
                            else{
                                var aa = "../TienTe_Controller?action=ShowCurrency&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSTT").html(result);
                                    }
                                });
                                $("#currencylang").html(result); // show chi tiết khu vực ở bảng bên trái
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenTT( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tentt";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../TienTe_Controller?action=SortTenTT&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../TienTe_Controller?action=SortTenTT&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortKyHieuTT( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "kyhieutt";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../TienTe_Controller?action=SortKyHieuTT&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../TienTe_Controller?action=SortKyHieuTT&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTTT( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tttt";
                if(sort == 'down'){
                    $('#titledskv3 div.down2').removeClass('down2');
                    $('#titledskv3 #sortkv3').addClass('up2');
                    var order1 = "asc";
                    var a = "../TienTe_Controller?action=SortTTTT&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up2').removeClass('up2');
                    $('#titledskv3 #sortkv3').addClass('down2');
                    var order2 = "desc";
                    var aa = "../TienTe_Controller?action=SortTTTT&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchTT(item, rightmsg){ //Search khu vuc
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tentt = $('#searchTienTe .tentt').val();
                var kyhieu = $('#searchTienTe .kyhieu').val();
                var macdinh = $('#searchTienTe .tinhtrang').val();
                var a = "../TienTe_Controller?action=Search&tentt="+tentt+"&kyhieu="+kyhieu+"&item="+item+"&macdinh="+macdinh;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSTT").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenTT( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tentt";
                var tentt = $('#searchTienTe .tentt').val();
                var kyhieu = $('#searchTienTe .kyhieu').val();
                var macdinh = $('#searchTienTe .tinhtrang').val();
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../TienTe_Controller?action=SortSearchTenTT&tentt="+tentt+"&kyhieu="+kyhieu+"&macdinh="+macdinh+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../TienTe_Controller?action=SortSearchTenTT&tentt="+tentt+"&kyhieu="+kyhieu+"&macdinh="+macdinh+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchKyHieuTT( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "kyhieutt";
                var tentt = $('#searchTienTe .tentt').val();
                var kyhieu = $('#searchTienTe .kyhieu').val();
                var macdinh = $('#searchTienTe .tinhtrang').val();
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../TienTe_Controller?action=SortSearchKyHieuTT&tentt="+tentt+"&kyhieu="+kyhieu+"&macdinh="+macdinh+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../TienTe_Controller?action=SortSearchKyHieuTT&tentt="+tentt+"&kyhieu="+kyhieu+"&macdinh="+macdinh+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTTT( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tttt";
                var tentt = $('#searchTienTe .tentt').val();
                var kyhieu = $('#searchTienTe .kyhieu').val();
                var macdinh = $('#searchTienTe .tinhtrang').val();
                if(sort == 'down'){
                    $('#titledskv3 div.down2').removeClass('down2');
                    $('#titledskv3 #sortkv3').addClass('up2');
                    var order1 = "asc";
                    var a = "../TienTe_Controller?action=SortSearchTTTT&tentt="+tentt+"&kyhieu="+kyhieu+"&macdinh="+macdinh+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up2').removeClass('up2');
                    $('#titledskv3 #sortkv3').addClass('down2');
                    var order2 = "desc";
                    var aa = "../TienTe_Controller?action=SortSearchTTTT&tentt="+tentt+"&kyhieu="+kyhieu+"&macdinh="+macdinh+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CheckAllTT(){
    x = document.dstiente.total.value;
    if(x > 1){
        optionTT = document.dstiente.optionTT;

        for(i=0; i<optionTT.length; i++)
        {
            if(!optionTT[i].checked){
                optionTT[i].click();
            }
        }
    }
    else{
        $('.optionTT').click();
    }
}
function DeleteTT( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=23";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "";
                total = document.dstiente.total.value;
                if(total > 1){
                    optionTT = document.dstiente.optionTT;
                    for(i = 0; i < optionTT.length; i++)
                    {
                        if(optionTT[i].checked)
                        {
                            x =   x  + optionTT[i].value + "-" ;
                        }
                    }
                }
                else{
                    if(document.dstiente.optionTT.checked){
                        x = document.dstiente.optionTT.value;
                    }
                }
                if(x == "") return;
                else{
                    var a = "../TienTe_Controller?action=DeleteTT&matte="+x+"&item="+item;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTT").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Edit_tentt(mann,  TenTTe, KyHieu) { // chuyển sang textbox để update 
    var y = "#tentte_"+mann;
    var z = "#kyhieu_"+mann;
    $(y).parent().html("<input type='textbox' class='text' style='width:100px' id="+y+" value='"+TenTTe+"'>");
    $(z).parent().html("<input type='textbox' class='text' style='width:100px' id="+z+" value='"+KyHieu+"'>");
}
function Save_editTTe( matte, mann, rightmsg) {   // Update tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=22";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var y = "#tentte_"+mann;
                var z = "#kyhieu_"+mann;
                var yy = document.getElementById(y);
                var zz = document.getElementById(z);
                var TenTTe = yy.value;
                var KyHieu = zz.value;
                var m = document.getElementById("currencyexist");
                var msg = m.value;
                var a = "../TienTe_Controller?action=Edit&matiente="+matte+"&TenTTe="+TenTTe+"&KyHieu="+KyHieu+"&mann="+mann;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){                        
                        $("#currencylang").html(result);
                        var aa = "../TienTe_Controller?action=ShowCurrency&item=1";  // hiển thị lại danh sách khu vực ở bảng bên phải
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#DSTT").html(result);
                            }
                        });
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowLangTT(MaTTe, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=20";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../TienTe_Controller?action=ShowLangTT&MaTTe="+MaTTe;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#currencylang").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateStatusTT(status, matte, msg, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=22";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../TienTe_Controller?action=CheckTienTe&matte="+matte;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        if(result == "error"){
                            var a = "../TienTe_Controller?action=UpdateStatusTT&matte="+matte+"&status="+status+"&item=1";
                            $.ajax({
                                url:a,
                                dataType:"html",
                                success:function(result){
                                    $("#DSTT").html(result);
                                }
                            });
                        }
                        else{
                            MSG(msg);
                            var aa = "../TienTe_Controller?action=ShowCurrency&item=1";  // hiển thị lại danh sách khu vực ở bảng bên phải
                            $.ajax({
                                url:aa,
                                dataType:"html",
                                success:function(result){
                                    $("#DSTT").html(result);
                                }
                            });
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End: Tiền tệ

// Start: Món ăn

function Food( item){
    var a = "../MonAn_Controller?action=Show&item="+item;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            
        }
    });
}
function AddFood(rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=25";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../MonAn_Controller?action=AddFood";
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#DSMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function OptionFood(rightmsg, mama){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../MonAn_Controller?action=OptionFood&mama="+mama;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#DSMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Addmoredvt(kyhieu, msgcheckunit, msgcheckcurrency){
    $('#dvt').append("<tr><td style='border: none; background: none;'><input type='text' style=' width: 100px; margin-bottom: 11px;' alt='"+msgcheckunit+"' onchange='CheckDVT(this.value, this.alt)' class='text' name='donvitinh'/></td><td style='border: none; background: none;'><input type='text' style=' width: 100px; margin-bottom: 11px;' class='text' onkeypress='return keypress(event)' alt='"+msgcheckcurrency+"' onchange='CheckTienTe(this.alt)' name='gia'/> "+kyhieu+"</td></tr>");

}
function UpdateStatusMA(status,  mama, rightmsg ){ 
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=26";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../MonAn_Controller?action=UpdateStatusMA&mama="+mama+"&status="+status+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });    
}
function SearchMA(item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var nhommonan = $('#searchMA .nhommonan').val();
                var TENMA = $('#searchMA .TENMA').val();
                var TENVT = $('#searchMA .TENVT').val();
                var GIA = $('#searchMA .GIA').val();
                var status = $('#searchMA .TINHTRANG').val();
                var a = "../MonAn_Controller?action=SearchMA&status="+status+"&nhommonan="+nhommonan+"&item="+item+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenNMA(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tennma";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortTenNMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortTenNMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenMA(sort, item, rightmsg){    // Sort tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenma";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortTenMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortTenMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenVT(sort, item, rightmsg){    // Sort tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenvt";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortTenVT&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortTenVT&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortGiaMA(sort, item, rightmsg){    // Sort tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tengiama";
                if(sort == 'down'){
                    $('#titledskv5 div.down1').removeClass('down1');
                    $('#titledskv5 #sortkv5').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortGiaMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv5 div.up1').removeClass('up1');
                    $('#titledskv5 #sortkv5').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortGiaMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTMA(sort, item, rightmsg){    // Sort tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenttma";
                if(sort == 'down'){
                    $('#titledskv6 div.down2').removeClass('down2');
                    $('#titledskv6 #sortkv6').addClass('up2');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortTTMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv6 div.up2').removeClass('up2');
                    $('#titledskv6 #sortkv6').addClass('down2');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortTTMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenNMA(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var nhommonan = $('#searchMA .nhommonan').val();
                var TENMA = $('#searchMA .TENMA').val();
                var TENVT = $('#searchMA .TENVT').val();
                var GIA = $('#searchMA .GIA').val();
                var status = $('#searchMA .TINHTRANG').val();
                var sortkv = "tennma";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortSearchTenNMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortSearchTenNMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });


}
function SortSearchTenMA(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var nhommonan = $('#searchMA .nhommonan').val();
                var TENMA = $('#searchMA .TENMA').val();
                var TENVT = $('#searchMA .TENVT').val();
                var GIA = $('#searchMA .GIA').val();
                var status = $('#searchMA .TINHTRANG').val();
                var sortkv = "tenma";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortSearchTenMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortSearchTenMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenVT(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var nhommonan = $('#searchMA .nhommonan').val();
                var TENMA = $('#searchMA .TENMA').val();
                var TENVT = $('#searchMA .TENVT').val();
                var GIA = $('#searchMA .GIA').val();
                var status = $('#searchMA .TINHTRANG').val();
                var sortkv = "tenvt";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortSearchTenVT&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortSearchTenVT&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchGiaMA(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var nhommonan = $('#searchMA .nhommonan').val();
                var TENMA = $('#searchMA .TENMA').val();
                var TENVT = $('#searchMA .TENVT').val();
                var GIA = $('#searchMA .GIA').val();
                var status = $('#searchMA .TINHTRANG').val();
                var sortkv = "tengiama";
                if(sort == 'down'){
                    $('#titledskv5 div.down1').removeClass('down1');
                    $('#titledskv5 #sortkv5').addClass('up1');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortSearchGiaMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv5 div.up1').removeClass('up1');
                    $('#titledskv5 #sortkv5').addClass('down1');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortSearchGiaMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTMA(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var nhommonan = $('#searchMA .nhommonan').val();
                var TENMA = $('#searchMA .TENMA').val();
                var TENVT = $('#searchMA .TENVT').val();
                var GIA = $('#searchMA .GIA').val();
                var status = $('#searchMA .TINHTRANG').val();
                var sortkv = "tenttma";
                if(sort == 'down'){
                    $('#titledskv6 div.down2').removeClass('down2');
                    $('#titledskv6 #sortkv6').addClass('up2');
                    var order1 = "asc";
                    var a = "../MonAn_Controller?action=SortSearchTTMA&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv6 div.up2').removeClass('up2');
                    $('#titledskv6 #sortkv6').addClass('down2');
                    var order2 = "desc";
                    var aa = "../MonAn_Controller?action=SortSearchTTMA&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&status="+status+"&nhommonan="+nhommonan+"&TENMA="+TENMA+"&TENVT="+TENVT+"&GIA="+GIA;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSMA").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CheckDVT(tendvt, msgunit){    
    if(tendvt != ""){
        var a = "../MonAn_Controller?action=CheckDVT&tendvt="+tendvt;
        $.ajax({
            url:a,
            dataType:"html",
            success:function(result){
                if(result != "exist"){
                    document.getElementById("checksubmit").value = "false";
                    MSG(msgunit);
                }
                else{
                    document.getElementById("checksubmit").value = "true";
                }
            }
        });
    }
}
function CheckTienTe(msgunit){
    var aa = "../MonAn_Controller?action=CheckTienTe";    
    $.ajax({
        url:aa,
        dataType:"html",
        success:function(result){
            if(result == "error"){
                document.getElementById("checkcurrency").value = "false";
                MSG(msgunit);
            }
            else{
                document.getElementById("checkcurrency").value = "true";
            }
        }
    });
}
function CheckSubmit(msgsubmit, msgunit, msgcurrency, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=25";
    var tenmonan = document.addFood.tenmonan.value;
    var tenviettat = document.addFood.tenviettat.value;
    var mota = document.addFood.mota.value;
    var Image = $('span.filename').html();    
    var submitOK = "true";
    var x = $('#checksubmit').val();
    var y = $('#checkcurrency').val();
    if(x == "false"){
        submitOK = "false";
        MSG(msgunit);
    }
    if(y == "false"){
        submitOK = "false";
        MSG(msgcurrency);
    }
    if(tenmonan == "" ||  tenviettat == "" || mota == "" || Image == "" ){
        submitOK = "false";
        MSG(msgsubmit);
    }
    if(submitOK == "false"){
        return false;
    }
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
            }
            else{
                MSG(rightmsg);
            }
        }
    }); 
}
function Upload(value){
    $('#uniform-file .filename').html(value) ;
}
function ShowLangMA(mama, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=24";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../MonAn_Controller?action=Detail&mama="+mama;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        var a = "../MonAn_Controller?action=ShowLangMA&mama="+mama;
                        $.ajax({
                            url:a,
                            dataType:"html",
                            success:function(result){
                                $("#FoodLang").html(result);
                            }
                        });
                        $("#DSMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });

 
}
function Edit_tenMA(mann, tenma) { // chuyển sang textbox để update
    var x = "#tenkv_"+mann;
    $(x).parent().html("<input type='textbox' class = 'text' style='width:250px' id="+x+" value='"+tenma+"'>");
}
function Save_editMA( mama, mann, rightmsg) {    // Update tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=26";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "#tenkv_"+mann;
                var z = document.getElementById(x);
                var tenma = z.value;
                var a = "../MonAn_Controller?action=EditTenMA&tenma="+tenma+"&mama="+mama+"&mann="+mann;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#FoodLang").html(result);
                        var aa = "../MonAn_Controller?action=Detail&mama="+mama;
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#DSMA").html(result);
                            }
                        });
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End: Món ăn

// Start: Khuyến mãi
function Promotion( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuyenMai_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function TaoKM( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=28";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuyenMai_Controller?action=ShowAdd&item="+item+"&malkm=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });

}
function ShowMonAn(manma){
    var x = "#"+manma;    
    var z = "#monan"+manma;
    var y = $(x).html();
    if(y=="+"){
        $(x).html("-");
    }
    else{
        $(x).html("+");
    }
    $(z).toggle();
}
function Discount(discount){    
    var mamonan = "";
    var gia = "";
    var rsgia = "";
    var saleprice = 0;
    var price = 0;
    var x = $('.count').val();
    
    if(x > 1){
        var discountfood = document.AddPromotion.discountfood;        
        for(i = 0; i < discountfood.length; i++)
        {
            document.AddPromotion.discountfood[i].value = discount;
            mamonan = document.AddPromotion.discountfood[i].alt;
            gia = document.AddPromotion.discountfood[i].lang;
            rsgia = "#rsgia"+mamonan;
            if(discount == "0"){
                price = gia;
            }
            else{
                saleprice = (gia*discount)/100;
                price = gia - saleprice;
            }            
            $(rsgia).html(price);
        }
    }
    else{
        document.AddPromotion.discountfoodd.value = discount;
    }       
}
function LayRsGia(discount, mama){    
    var a = "../KhuyenMai_Controller?action=LayRsGia&mama="+mama+"&discount="+discount;
    var rsgia = "#rsgia"+mama;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $(rsgia).html(result);
        }
    });
}
function ShowDSMA(item, manma){
    var a = "../KhuyenMai_Controller?action=ShowDSMA&manma="+manma+"&item="+item;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){            
            $('#tableDSMA').html(result);
        }
    });
}
function addpromotion(msgsubmit, msgright, msgdate, msgcheckdatepromotion){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=28";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var loaikm = document.AddPromotion.promotiontype.value;
                var datestart = document.AddPromotion.datestart.value;
                var enddate = document.AddPromotion.enddate.value;
                var promotionname = document.AddPromotion.promotionname.value;
                var content = document.AddPromotion.content.value;
                if(loaikm == "" || datestart=="" || enddate=="" || promotionname=="" || content=="" ){
                    MSG(msgsubmit);
                }
                else{
                    var x = "../KhuyenMai_Controller?action=CheckDate&tungay="+datestart+"&denngay="+enddate;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var b = "../KhuyenMai_Controller?action=CheckDateKM&tungay="+datestart+"&denngay="+enddate+"&loaikm="+loaikm;
                                $.ajax({
                                    url:b,
                                    dataType:"html",
                                    success:function(result){
                                        if(result == "true"){
                                            var a = "../KhuyenMai_Controller?action=addpromotion&loaikm="+loaikm+"&datestart="+datestart+"&enddate="+enddate+"&promotionname="+promotionname+"&content="+content+"&item=1";
                                            $.ajax({
                                                url:a,
                                                dataType:"html",
                                                success:function(result){
                                                    $('#content').html(result);
                                                }
                                            });
                                        }
                                        else{
                                            MSG(msgcheckdatepromotion);
                                        }
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(msgright);
            }
        }
    });
}
function addpromotionbill(msgsubmit, rightmsg, msgdate, msgcheckdatepromotion){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=28";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var loaikm = document.AddPromotion.promotiontype.value;
                var datestart = document.AddPromotion.datestart.value;
                var enddate = document.AddPromotion.enddate.value;
                var promotionname = document.AddPromotion.promotionname.value;
                var content = document.AddPromotion.content.value;
                var condition = document.AddPromotion.condition.value;
                var discount = document.AddPromotion.discount.value;
                if(loaikm=="" || datestart=="" || enddate=="" || promotionname=="" || content=="" || condition=="" || discount==""){
                    MSG(msgsubmit);
                }
                else{
                    var x = "../KhuyenMai_Controller?action=CheckDate&tungay="+datestart+"&denngay="+enddate;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var b = "../KhuyenMai_Controller?action=CheckDateKM&tungay="+datestart+"&denngay="+enddate+"&loaikm="+loaikm;
                                $.ajax({
                                    url:b,
                                    dataType:"html",
                                    success:function(result){
                                        if(result == "true"){
                                            var a = "../KhuyenMai_Controller?action=AddPromotionBill&loaikm="+loaikm+"&datestart="+datestart+"&enddate="+enddate+"&promotionname="+promotionname+"&content="+content+"&condition="+condition+"&discount="+discount+"&item=1";
                                            $.ajax({
                                                url:a,
                                                dataType:"html",
                                                success:function(result){
                                                    $('#content').html(result);
                                                }
                                            });
                                        }
                                        else{
                                            MSG(msgcheckdatepromotion);
                                        }
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function updatepromotionbill(msgsubmit, rightmsg, makm, msgdate, msgcheckdatepromotion){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=29";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var datestart = document.AddPromotion.datestart.value;
                var enddate = document.AddPromotion.enddate.value;
                var promotionname = document.AddPromotion.promotionname.value;
                var content = document.AddPromotion.content.value;
                var condition = document.AddPromotion.condition.value;
                var discount = document.AddPromotion.discount.value;
                if(datestart=="" || enddate=="" || promotionname=="" || content=="" || condition=="" || discount==""){
                    MSG(msgsubmit);
                }
                else{
                    var x = "../KhuyenMai_Controller?action=CheckDate&tungay="+datestart+"&denngay="+enddate;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var b = "../KhuyenMai_Controller?action=CheckDateKMUpdate&tungay="+datestart+"&denngay="+enddate+"&loaikm=2&makm="+makm;
                                $.ajax({
                                    url:b,
                                    dataType:"html",
                                    success:function(result){
                                        if(result == "true"){
                                            var a = "../KhuyenMai_Controller?action=updatepromotionbill&datestart="+datestart+"&enddate="+enddate+"&promotionname="+promotionname+"&content="+content+"&condition="+condition+"&discount="+discount+"&item=1&makm="+makm;
                                            $.ajax({
                                                url:a,
                                                dataType:"html",
                                                success:function(result){
                                                    $('#content').html(result);
                                                }
                                            });
                                        }
                                        else{
                                            MSG(msgcheckdatepromotion);
                                        }
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateDetailPromotionDay( msgsubmit, rightmsg, makm, msgdate, msgcheckdatepromotion){    
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=29";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var datestart = document.AddPromotion.datestart.value;
                var enddate = document.AddPromotion.enddate.value;
                var promotionname = document.AddPromotion.promotionname.value;
                var content = document.AddPromotion.content.value;
                var msgupdatesuc = document.getElementById("updatesuccess").value;                
                if(datestart=="" || enddate=="" || promotionname=="" || content==""){
                    MSG(msgsubmit);
                }
                else{
                    var x = "../KhuyenMai_Controller?action=CheckDate&tungay="+datestart+"&denngay="+enddate;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var b = "../KhuyenMai_Controller?action=CheckDateKMUpdate&tungay="+datestart+"&denngay="+enddate+"&loaikm=1&makm="+makm;
                                $.ajax({
                                    url:b,
                                    dataType:"html",
                                    success:function(result){
                                        if(result == "true"){
                                            var a = "../KhuyenMai_Controller?action=UpdateDetailPromotionDay&datestart="+datestart+"&enddate="+enddate+"&promotionname="+promotionname+"&content="+content+"&item=1&makm="+makm;
                                            $.ajax({
                                                url:a,
                                                dataType:"html",
                                                success:function(result){
                                                    $('#content').html(result);
                                                    MSG(msgupdatesuc);
                                                }
                                            });
                                        }
                                        else{
                                            MSG(msgcheckdatepromotion);
                                        }
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenMAKM(sort, item, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenma = $('#searchaddpro .tenma').val();
                var ngaythu = $('#searchaddpro .ngaythu').val();
                var gia = $('#searchaddpro .gia').val();
                var giamgia = $('#searchaddpro .giamgia').val();
                var sortkv = "tenmakm";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortSearchTenMAKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm+"&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&giamgia="+giamgia;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortSearchTenMAKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm+"&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&giamgia="+giamgia;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayKM(sort, item, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenma = $('#searchaddpro .tenma').val();
                var ngaythu = $('#searchaddpro .ngaythu').val();
                var gia = $('#searchaddpro .gia').val();
                var giamgia = $('#searchaddpro .giamgia').val();
                var sortkv = "ngaykm";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortSearchNgayKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm+"&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&giamgia="+giamgia;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortSearchNgayKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm+"&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&giamgia="+giamgia;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchGiaKM(sort, item, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenma = $('#searchaddpro .tenma').val();
                var ngaythu = $('#searchaddpro .ngaythu').val();
                var gia = $('#searchaddpro .gia').val();
                var giamgia = $('#searchaddpro .giamgia').val();
                var sortkv = "giakm";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortSearchGiaKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm+"&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&giamgia="+giamgia;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortSearchGiaKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm+"&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&giamgia="+giamgia;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenMAKM(sort, item, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenmakm";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortTenMAKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortTenMAKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayKM(sort, item, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaykm";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortNgayKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortNgayKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortGiaKM(sort, item, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "giakm";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortGiaKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortGiaKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makm="+makm;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#detailproday").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchKM( item, rightmsg, manma){ // Search bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenma = $('#searchKM .tenmasearch').val();
                var ngaythu = $('#searchKM .ngaythusearch').val();
                var gia = $('#searchKM .giasearch').val();                
                var a = "../KhuyenMai_Controller?action=SearchKM&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&manma="+manma;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#tableDSMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenKM(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenkm";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortTenKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortTenKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayBDKM(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaybdkm";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortNgayBDKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortNgayBDKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayKTKM(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngayktkm";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortNgayKTKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortNgayKTKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTKM(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ttkm";
                if(sort == 'down'){
                    $('#titledskv4 div.down2').removeClass('down2');
                    $('#titledskv4 #sortkv4').addClass('up2');
                    var order1 = "asc";
                    var a = "../KhuyenMai_Controller?action=SortTTKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up2').removeClass('up2');
                    $('#titledskv4 #sortkv4').addClass('down2');
                    var order2 = "desc";
                    var aa = "../KhuyenMai_Controller?action=SortTTKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchListKM(item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var TENKM = $('#searchListKM .TENKM').val();
                var BATDAU = $('#searchListKM .BATDAU').val();
                var KETTHUC = $('#searchListKM .KETTHUC').val();
                var TINHTRANG = $('#searchListKM .TINHTRANG').val();
                if(BATDAU != "" && KETTHUC != ""){
                    var a = "../KhuyenMai_Controller?action=CheckDate&tungay="+BATDAU+"&denngay="+KETTHUC;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var a = "../KhuyenMai_Controller?action=SearchListKM&TENKM="+TENKM+"&BATDAU="+BATDAU+"&item="+item+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        $("#content").html(result);
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
                else{
                    var c = "../KhuyenMai_Controller?action=SearchListKM&TENKM="+TENKM+"&BATDAU="+BATDAU+"&item="+item+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                    $.ajax({
                        url:c,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenKM(sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var TENKM = $('#searchListKM .TENKM').val();
                var BATDAU = $('#searchListKM .BATDAU').val();
                var KETTHUC = $('#searchListKM .KETTHUC').val();
                var TINHTRANG = $('#searchListKM .TINHTRANG').val();
                if(BATDAU != "" && KETTHUC != ""){
                    var a = "../KhuyenMai_Controller?action=CheckDate&tungay="+BATDAU+"&denngay="+KETTHUC;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "tenkm";
                                if(sort == 'down'){
                                    $('#titledskv1 div.down1').removeClass('down1');
                                    $('#titledskv1 #sortkv1').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../KhuyenMai_Controller?action=SortSearchTenKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv1 div.up1').removeClass('up1');
                                    $('#titledskv1 #sortkv1').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../KhuyenMai_Controller?action=SortSearchTenKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
                else{                    
                    var sortkv = "tenkm";
                    if(sort == 'down'){
                        $('#titledskv1 div.down1').removeClass('down1');
                        $('#titledskv1 #sortkv1').addClass('up1');
                        var order1 = "asc";
                        var c = "../KhuyenMai_Controller?action=SortSearchTenKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:c,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }
                    if(sort == 'up'){
                        $('#titledskv1 div.up1').removeClass('up1');
                        $('#titledskv1 #sortkv1').addClass('down1');
                        var order2 = "desc";
                        var aa = "../KhuyenMai_Controller?action=SortSearchTenKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayBDKM(sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var TENKM = $('#searchListKM .TENKM').val();
                var BATDAU = $('#searchListKM .BATDAU').val();
                var KETTHUC = $('#searchListKM .KETTHUC').val();
                var TINHTRANG = $('#searchListKM .TINHTRANG').val();
                if(BATDAU != "" && KETTHUC != ""){
                    var a = "../KhuyenMai_Controller?action=CheckDate&tungay="+BATDAU+"&denngay="+KETTHUC;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "ngaybdkm";
                                if(sort == 'down'){
                                    $('#titledskv2 div.down1').removeClass('down1');
                                    $('#titledskv2 #sortkv2').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../KhuyenMai_Controller?action=SortSearchNgayBDKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv2 div.up1').removeClass('up1');
                                    $('#titledskv2 #sortkv2').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../KhuyenMai_Controller?action=SortSearchNgayBDKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
                else{
                    var sortkv = "ngaybdkm";
                    if(sort == 'down'){
                        $('#titledskv2 div.down1').removeClass('down1');
                        $('#titledskv2 #sortkv2').addClass('up1');
                        var order1 = "asc";
                        var c = "../KhuyenMai_Controller?action=SortSearchNgayBDKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:c,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }
                    if(sort == 'up'){
                        $('#titledskv2 div.up1').removeClass('up1');
                        $('#titledskv2 #sortkv2').addClass('down1');
                        var order2 = "desc";
                        var aa = "../KhuyenMai_Controller?action=SortSearchNgayBDKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayKTKM(sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var TENKM = $('#searchListKM .TENKM').val();
                var BATDAU = $('#searchListKM .BATDAU').val();
                var KETTHUC = $('#searchListKM .KETTHUC').val();
                var TINHTRANG = $('#searchListKM .TINHTRANG').val();
                if(BATDAU != "" && KETTHUC != ""){
                    var a = "../KhuyenMai_Controller?action=CheckDate&tungay="+BATDAU+"&denngay="+KETTHUC;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "ngayktkm";
                                if(sort == 'down'){
                                    $('#titledskv3 div.down1').removeClass('down1');
                                    $('#titledskv3 #sortkv3').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../KhuyenMai_Controller?action=SortSearchNgayKTKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv3 div.up1').removeClass('up1');
                                    $('#titledskv3 #sortkv3').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../KhuyenMai_Controller?action=SortSearchNgayKTKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }

                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
                else{
                    var sortkv = "ngayktkm";
                    if(sort == 'down'){
                        $('#titledskv3 div.down1').removeClass('down1');
                        $('#titledskv3 #sortkv3').addClass('up1');
                        var order1 = "asc";
                        var c = "../KhuyenMai_Controller?action=SortSearchNgayKTKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:c,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }
                    if(sort == 'up'){
                        $('#titledskv3 div.up1').removeClass('up1');
                        $('#titledskv3 #sortkv3').addClass('down1');
                        var order2 = "desc";
                        var aa = "../KhuyenMai_Controller?action=SortSearchNgayKTKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }

                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });

}
function SortSearchTTKM(sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var TENKM = $('#searchListKM .TENKM').val();
                var BATDAU = $('#searchListKM .BATDAU').val();
                var KETTHUC = $('#searchListKM .KETTHUC').val();
                var TINHTRANG = $('#searchListKM .TINHTRANG').val();
                if(BATDAU != "" && KETTHUC != ""){
                    var a = "../KhuyenMai_Controller?action=CheckDate&tungay="+BATDAU+"&denngay="+KETTHUC;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "ttkm";
                                if(sort == 'down'){
                                    $('#titledskv4 div.down2').removeClass('down2');
                                    $('#titledskv4 #sortkv4').addClass('up2');
                                    var order1 = "asc";
                                    var a = "../KhuyenMai_Controller?action=SortSearchTTKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv4 div.up2').removeClass('up2');
                                    $('#titledskv4 #sortkv4').addClass('down2');
                                    var order2 = "desc";
                                    var aa = "../KhuyenMai_Controller?action=SortSearchTTKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#content").html(result);
                                        }
                                    });
                                }

                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
                else{
                    var sortkv = "ttkm";
                    if(sort == 'down'){
                        $('#titledskv4 div.down2').removeClass('down2');
                        $('#titledskv4 #sortkv4').addClass('up2');
                        var order1 = "asc";
                        var c = "../KhuyenMai_Controller?action=SortSearchTTKM&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:c,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }
                    if(sort == 'up'){
                        $('#titledskv4 div.up2').removeClass('up2');
                        $('#titledskv4 #sortkv4').addClass('down2');
                        var order2 = "desc";
                        var aa = "../KhuyenMai_Controller?action=SortSearchTTKM&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&TENKM="+TENKM+"&BATDAU="+BATDAU+"&KETTHUC="+KETTHUC+"&TINHTRANG="+TINHTRANG;
                        $.ajax({
                            url:aa,
                            dataType:"html",
                            success:function(result){
                                $("#content").html(result);
                            }
                        });
                    }

                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });

}
function ShowLangKM(makm, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuyenMai_Controller?action=ShowLangKM&makm="+makm;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Edit_KM(mann,  tenkm, noidung) { // chuyển sang textbox để update
    var y = "#tenkm_"+mann;
    var z = "#noidungkm_"+mann;
    $(y).parent().html("<textarea id="+y+" class = 'textarea' style='width: 200px; height: 75px;'>"+tenkm+"</textarea>");
    $(z).parent().html("<textarea id="+z+" class = 'textarea' style='width: 260px; height: 75px;'>"+noidung+"</textarea>");
}
function Save_editKM( makm, mann, rightmsg) {   
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=29";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var y = "#tenkm_"+mann;
                var z = "#noidungkm_"+mann;
                var yy = document.getElementById(y);
                var zz = document.getElementById(z);
                var TenKM = yy.value;
                var NoiDung = zz.value;
                alert(NoiDung);
                var a = "../KhuyenMai_Controller?action=EditLang&makm="+makm+"&TenKM="+TenKM+"&NoiDung="+NoiDung+"&mann="+mann;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){                        
                        $("#content").html(result); 
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateStatusKM(status,  makm, rightmsg ){  // update tình trạng khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=29";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuyenMai_Controller?action=UpdateStatusKM&makm="+makm+"&status="+status+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function LoaiKM(malkm){
    if(malkm == "2"){
        var a = "../KhuyenMai_Controller?action=KMTheoHoaDon&malkm="+malkm;
        $.ajax({
            url:a,
            dataType:"html",
            success:function(result){
                $("#content").html(result);
            }
        });
    }
    else{
        var aa = "../KhuyenMai_Controller?action=ShowAdd&item=1&malkm="+malkm;
        $.ajax({
            url:aa,
            dataType:"html",
            success:function(result){
                $("#content").html(result);
            }
        });
    }
}
function UpdatePromotion(makm, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=29";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../KhuyenMai_Controller?action=UpdatePromotion&makm="+makm+"&item=1";
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function DetailPromotionDay(makm, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../KhuyenMai_Controller?action=DetailPromotionDay&makm="+makm;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowDetailPromotionDay(rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../KhuyenMai_Controller?action=ShowDetailPromotionDay&makm="+makm+"&item=1";
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function AddProDay( makm, msgsubmit, msgchkpro, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=28";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var mamonan = "";
                var discount = document.AddDetailProDay.discount.value;
                var total = document.AddDetailProDay.total.value;
                if(total > 1){
                    var mama = document.AddDetailProDay.chkma;
                }
                else{
                    mamonan = document.AddDetailProDay.chkma.alt;
                }
                var mant = document.AddDetailProDay.chknt;                
                var mangay = "";
                if(discount == "" || mama == "" || mant == ""){
                    MSG(msgsubmit);
                }
                else{
                    if(total > 1){
                        for(i=0; i<mama.length; i++){
                            if(mama[i].checked){
                                mamonan = mamonan + mama[i].alt + ";";
                            }
                        }
                    }
                    for(j=0; j<mant.length; j++){
                        if(mant[j].checked){
                            mangay = mangay + mant[j].alt + ";";
                        }
                    }
                    if(mamonan == "" || mangay == ""){
                        MSG(msgsubmit);
                    }
                    else{
                        var a = "../KhuyenMai_Controller?action=CheckAddProDay&makm="+makm+"&mamonan="+mamonan+"&mangay="+mangay;
                        $.ajax({
                            url:a,
                            dataType:"html",
                            success:function(result){
                                if(result == "exist"){
                                    MSG(msgchkpro);
                                }
                                else{
                                    var aa = "../KhuyenMai_Controller?action=AddProDay&makm="+makm+"&discount="+discount+"&mamonan="+mamonan+"&mangay="+mangay+"&item=1";
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#detailproday").html(result);
                                        }
                                    });
                                }
                            }
                        });
                    }
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function DeleteProDay(makmtn, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuyenMai_Controller?action=DeleteProDay&makmtn="+makmtn+"&makm="+makm+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#detailproday").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowListFood(item, manma ){
    var a = "../KhuyenMai_Controller?action=ShowListFood&manma="+manma+"&item="+item;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#dsma").html(result);
        }
    });
}
function ViewDetailProDay(item, rightmsg, makm){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuyenMai_Controller?action=ViewDetailProDay&makm="+makm+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#detailproday").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchAddPro( item, rightmsg, makm){ // Search bàn
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=27";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenma = $('#searchaddpro .tenma').val();
                var ngaythu = $('#searchaddpro .ngaythu').val();
                var gia = $('#searchaddpro .gia').val();
                var giamgia = $('#searchaddpro .giamgia').val();
                var a = "../KhuyenMai_Controller?action=SearchAddPro&tenma="+tenma+"&ngaythu="+ngaythu+"&item="+item+"&gia="+gia+"&makm="+makm+"&giamgia="+giamgia;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#detailproday").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateGiamGia(makmtn, giamgia, makm, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=29";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhuyenMai_Controller?action=UpdateGiamGia&makmtn="+makmtn+"&giamgia="+giamgia+"&item=1&makm="+makm;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#detailproday").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function DeleteKM( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=61";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "";
                total = document.dskm.total.value;
                if(total > 1){
                    optionKM = document.dskm.optionKM;
                    for(i = 0; i < optionKM.length; i++)
                    {
                        if(optionKM[i].checked)
                        {
                            x =   x  + optionKM[i].value + "-" ;
                        }
                    }
                }
                else{
                    if(document.dskm.optionKM.checked){
                        x = document.dskm.optionKM.value;
                    }
                }
                if(x == "") return;
                else{
                    var a = "../KhuyenMai_Controller?action=DeleteKM&makm="+x+"&item="+item;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#content").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End khuyến mãi

// Start tùy chọn

function Option( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=30";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../TuyChon_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CreateTC(msg, rightmsg, msgchecksubmit) {  // Tạo khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=31";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tcname = document.addTC.tcname.value;
                if(tcname == ""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../TuyChon_Controller?action=Add&tcname="+tcname;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "exist"){
                                MSG(msg);
                            }
                            else{
                                var aa = "../TuyChon_Controller?action=ShowTC&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSTC").html(result);
                                    }
                                });
                                $("#TClang").html(result); // show chi tiết khu vực ở bảng bên trái
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Edit_tentc(mann, tentc) { // chuyển sang textbox để update
    var x = "#tentc_"+mann;
    $(x).parent().html("<input type='textbox' class = 'text' style='width:100px' id="+x+" value='"+tentc+"'>");
}
function Save_edittc( matc, mann, rightmsg) {    // Update tên khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=32";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "#tentc_"+mann;
                var z = document.getElementById(x);
                var tentc = z.value;
                var m = document.getElementById("optionexist");
                var msg = m.value;
                var a = "../TuyChon_Controller?action=Edit&tentc="+tentc+"&matc="+matc+"&mann="+mann;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        if(result == "exist"){
                            MSG(msg);
                        }
                        else{
                            $("#TClang").html(result);
                            var aa = "../TuyChon_Controller?action=ShowTC&item=1";  // hiển thị lại danh sách khu vực ở bảng bên phải
                            $.ajax({
                                url:aa,
                                dataType:"html",
                                success:function(result){
                                    $("#DSTC").html(result);
                                }
                            });
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchTC(item, rightmsg){ //Search khu vuc
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=30";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tentc = $('#searchTC input').val();
                var a = "../TuyChon_Controller?action=Search&tentc="+tentc+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSTC").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenTC(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=30";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tentc";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../TuyChon_Controller?action=SortTenTC&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTC").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../TuyChon_Controller?action=SortTenTC&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTC").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenTC(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=30";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tentc = $('#searchTC input').val();
                var sortkv = "tentc";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../TuyChon_Controller?action=SortSearchTenTC&tentc="+tentc+"&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTC").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../TuyChon_Controller?action=SortSearchTenTC&tentc="+tentc+"&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTC").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowLangTC(matc, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=30";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../TuyChon_Controller?action=ShowLangTC&matc="+matc;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#TClang").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CheckOption(tentc, msgoption, mama, msgckoption){
    var a = "../TuyChon_Controller?action=CheckOption&tentc="+tentc;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            if(result != "exist"){
                MSG(msgckoption);
            }
            else{
                var aa = "../TuyChon_Controller?action=CheckOptionFood&tentc="+tentc+"&mama="+mama;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        if(result == "exist"){
                            MSG(msgoption);
                        }
                        else{
                            var b = "../MonAn_Controller?action=AddOptionFood&tentc="+tentc+"&mama="+mama;
                            $.ajax({
                                url:b,
                                dataType:"html",
                                success:function(result){
                                    $("#tuychonma").html(result);
                                }
                            });
                        }
                    }
                });
            }
        }
    });
}
function DeleteOptionFood(rightmsg, mama, matc){
    var a = "../MonAn_Controller?action=DeleteOptionFood&mama="+mama+"&matc="+matc;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#tuychonma").html(result);
        }
    });
}
function Addmoreoption(msgcheckoption, mama, msgchkoption){
    $('#tuychonma').append("<tr><td style='border: none; background: none;'><input type='text' style=' width: 100px; margin-bottom: 11px; margin-right: 15px; float: left;' alt='"+msgcheckoption+"' id='"+mama+"' name='"+msgchkoption+"' onchange='CheckOption(this.value, this.alt, this.id, this.name)' class='text' /><img style=' height: 18px; width: 18px; cursor: pointer; margin-left: 1px; margin-top: 2px;' alt='' src='../images/addmoney.png'></td></tr>");

}
// End tùy chọn

// Start Loại khách hàng

function CustomerType( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../LoaiKH_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function AddCustomerType(msglkh, rightmsg, msgchecksubmit){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=34";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var customertype = document.addCustomerType.customertype.value;
                var mark = document.addCustomerType.mark.value;
                var reduction = document.addCustomerType.reduction.value;
                if(customertype == "" || mark == "" || reduction == ""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var b = "../LoaiKH_Controller?action=CheckTenLKH&customertype="+customertype;
                    $.ajax({
                        url:b,
                        dataType:"html",
                        success:function(result){
                            if(result == "exist"){
                                MSG(msglkh);
                            }
                            else{
                                var a = "../LoaiKH_Controller?action=Add&customertype="+customertype+"&mark="+mark+"&reduction="+reduction;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        var aa = "../LoaiKH_Controller?action=ShowLoaiKH&item=1";
                                        $.ajax({
                                            url:aa,
                                            dataType:"html",
                                            success:function(result){
                                                $("#DSLKH").html(result);
                                            }
                                        });
                                        $("#customertypelang").html(result);
                                    }
                                });
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowLangCT(MaLKH, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../LoaiKH_Controller?action=ShowLangCT&MaLKH="+MaLKH;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#customertypelang").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Edit_LKH(mann, tenlkh, chietkhau, sodiem) { // chuyển sang textbox để update
    var x = "#tenlkh_"+mann;
    var y = "#chietkhau_"+mann;
    var z = "#sodiem_"+mann;
    $(x).parent().html("<input type='textbox' class = 'text' style='width:160px' id="+x+" value='"+tenlkh+"'>");
    $(y).parent().html("<input type='textbox' onkeypress='return keypress(event)' maxlength='2' class = 'text' style='width:60px' id="+y+" value='"+chietkhau+"'>");
    $(z).parent().html("<input type='textbox' onkeypress='return keypress(event)' class = 'text' style='width:60px' id="+z+" value='"+sodiem+"'>");
}
function Save_editLKH( malkh, mann, rightmsg) {    // Update tên khu vực
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=35";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "#tenlkh_"+mann;
                var y = "#chietkhau_"+mann;
                var z = "#sodiem_"+mann;
                var xx = document.getElementById(x);
                var yy = document.getElementById(y);
                var zz = document.getElementById(z);
                var tenlkh = xx.value;
                var chietkhau = yy.value;
                var sodiem = zz.value;
                var b = "../LoaiKH_Controller?action=CheckTenLKHEdit&tenlkh="+tenlkh+"&malkh="+malkh;
                var m = document.getElementById("customertypeexist");
                var msg = m.value;
                $.ajax({
                    url:b,
                    dataType:"html",
                    success:function(result){
                        if(result == "exist"){
                            MSG(msg);
                        }
                        else{
                            var a = "../LoaiKH_Controller?action=Edit&tenlkh="+tenlkh+"&malkh="+malkh+"&mann="+mann+"&chietkhau="+chietkhau+"&sodiem="+sodiem;
                            $.ajax({
                                url:a,
                                dataType:"html",
                                success:function(result){
                                    $("#customertypelang").html(result);
                                    var aa = "../LoaiKH_Controller?action=ShowLoaiKH&item=1";
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLKH").html(result);
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchLKH(item, rightmsg){ //Search khu vuc
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenlkh = $('#searchLKH .tenlkh').val();
                var sodiem = $('#searchLKH .sodiem').val();
                var chietkhau = $('#searchLKH .chietkhau').val();
                var a = "../LoaiKH_Controller?action=Search&tenlkh="+tenlkh+"&sodiem="+sodiem+"&chietkhau="+chietkhau+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSLKH").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenLKH(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenlkh";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../LoaiKH_Controller?action=SortTenLKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LoaiKH_Controller?action=SortTenLKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSoDiem(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "sodiem";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../LoaiKH_Controller?action=SortSoDiem&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LoaiKH_Controller?action=SortSoDiem&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortChietKhau(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "chietkhau";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../LoaiKH_Controller?action=SortChietKhau&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LoaiKH_Controller?action=SortChietKhau&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenLKH(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenlkh = $('#searchLKH .tenlkh').val();
                var sodiem = $('#searchLKH .sodiem').val();
                var chietkhau = $('#searchLKH .chietkhau').val();
                var sortkv = "tenlkh";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../LoaiKH_Controller?action=SortSearchTenLKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tenlkh="+tenlkh+"&sodiem="+sodiem+"&chietkhau="+chietkhau;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LoaiKH_Controller?action=SortSearchTenLKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tenlkh="+tenlkh+"&sodiem="+sodiem+"&chietkhau="+chietkhau;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchSoDiem(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenlkh = $('#searchLKH .tenlkh').val();
                var sodiem = $('#searchLKH .sodiem').val();
                var chietkhau = $('#searchLKH .chietkhau').val();
                var sortkv = "sodiem";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../LoaiKH_Controller?action=SortSearchSoDiem&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tenlkh="+tenlkh+"&sodiem="+sodiem+"&chietkhau="+chietkhau;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LoaiKH_Controller?action=SortSearchSoDiem&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tenlkh="+tenlkh+"&sodiem="+sodiem+"&chietkhau="+chietkhau;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchChietKhau(sort, item, rightmsg){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=33";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenlkh = $('#searchLKH .tenlkh').val();
                var sodiem = $('#searchLKH .sodiem').val();
                var chietkhau = $('#searchLKH .chietkhau').val();
                var sortkv = "chietkhau";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../LoaiKH_Controller?action=SortSearchChietKhau&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tenlkh="+tenlkh+"&sodiem="+sodiem+"&chietkhau="+chietkhau;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LoaiKH_Controller?action=SortSearchChietKhau&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tenlkh="+tenlkh+"&sodiem="+sodiem+"&chietkhau="+chietkhau;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}

// End Loại khách hàng

// Start Khách hàng

function Customer( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhachHang_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CreateCustomer(rightmsg, msgchecksubmit){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=37";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var lkh = document.createcustomer.lkh.value;
                var tenkh = document.createcustomer.tenkh.value;
                var diachi = document.createcustomer.diachi.value;
                var sodt = document.createcustomer.sodt.value;
                var birthday = document.createcustomer.birthday.value;
                if(lkh =="" || tenkh ==""  || diachi =="" || sodt =="" || birthday==""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../KhachHang_Controller?action=CreateCustomer&lkh="+lkh+"&tenkh="+tenkh+"&diachi="+diachi+"&sodt="+sodt+"&birthday="+birthday;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "success"){
                                var aa = "../KhachHang_Controller?action=ShowDSKH&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSKH").html(result);
                                    }
                                });
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortHoTenKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenkh";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortHoTenKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortHoTenKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortDiemKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "diemkh";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortDiemKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortDiemKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortLoaiKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "loaikh";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortLoaiKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortLoaiKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ttkh";
                if(sort == 'down'){
                    $('#titledskv4 div.down2').removeClass('down2');
                    $('#titledskv4 #sortkv4').addClass('up2');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortTTKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up2').removeClass('up2');
                    $('#titledskv4 #sortkv4').addClass('down2');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortTTKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchCustomer( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var hoten = $('#searchKH .hoten').val();
                var sodiem = $('#searchKH .sodiem').val();
                var loaikh = $('#searchKH .loaikh').val();
                var tinhtrang = $('#searchKH .tinhtrang').val();
                var a = "../KhachHang_Controller?action=SearchCustomer&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSKH").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchHoTenKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var hoten = $('#searchKH .hoten').val();
                var sodiem = $('#searchKH .sodiem').val();
                var loaikh = $('#searchKH .loaikh').val();
                var tinhtrang = $('#searchKH .tinhtrang').val();
                var sortkv = "tenkh";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortSearchHoTenKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortSearchHoTenKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchDiemKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var hoten = $('#searchKH .hoten').val();
                var sodiem = $('#searchKH .sodiem').val();
                var loaikh = $('#searchKH .loaikh').val();
                var tinhtrang = $('#searchKH .tinhtrang').val();
                var sortkv = "diemkh";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortSearchDiemKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortSearchDiemKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchLoaiKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var hoten = $('#searchKH .hoten').val();
                var sodiem = $('#searchKH .sodiem').val();
                var loaikh = $('#searchKH .loaikh').val();
                var tinhtrang = $('#searchKH .tinhtrang').val();
                var sortkv = "loaikh";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortSearchLoaiKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortSearchLoaiKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTKH(item, sort, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var hoten = $('#searchKH .hoten').val();
                var sodiem = $('#searchKH .sodiem').val();
                var loaikh = $('#searchKH .loaikh').val();
                var tinhtrang = $('#searchKH .tinhtrang').val();
                var sortkv = "ttkh";
                if(sort == 'down'){
                    $('#titledskv4 div.down2').removeClass('down2');
                    $('#titledskv4 #sortkv4').addClass('up2');
                    var order1 = "asc";
                    var a = "../KhachHang_Controller?action=SortSearchTTKH&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up2').removeClass('up2');
                    $('#titledskv4 #sortkv4').addClass('down2');
                    var order2 = "desc";
                    var aa = "../KhachHang_Controller?action=SortSearchTTKH&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&hoten="+hoten+"&sodiem="+sodiem+"&loaikh="+loaikh+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSKH").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateStatusKH(tinhtrang,  makh, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=38";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhachHang_Controller?action=UpdateStatusKH&tinhtrang="+tinhtrang+"&makh="+makh+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSKH").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateLKH(malkh,  makh, rightmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=38";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhachHang_Controller?action=UpdateLKH&malkh="+malkh+"&makh="+makh+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSKH").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateDetailKH( makh, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=36";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../KhachHang_Controller?action=Detail&makh="+makh;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#ShowTaoKH").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateDetailkh(makh,  msg, rightmsg, msgchecksubmit){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=38";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var loaikh = document.createcustomer.loaikh.value;
                var tenkh = document.createcustomer.tenkh.value;
                var diachi = document.createcustomer.diachi.value;
                var sodt = document.createcustomer.sodt.value;
                var birthday = document.createcustomer.birthday.value;
                if(tenkh =="" || diachi =="" || sodt =="" || birthday==""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var a = "../KhachHang_Controller?action=UpdateDetailkh&tenkh="+tenkh+"&diachi="+diachi+"&sodt="+sodt+"&birthday="+birthday+"&makh="+makh+"&loaikh="+loaikh;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "success"){
                                var aa = "../KhachHang_Controller?action=ShowDSKH&item=1";
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSKH").html(result);
                                    }
                                });
                                MSG(msg);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function DoiDiem(rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=39";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "../KhachHang_Controller?action=DoiDiem";
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateDoiDiem(rightmsg, msgdetail, submitmsg ){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=39";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sodiem = document.doidiem.sodiem.value;
                var sotien = document.doidiem.sotien.value;
                if(sodiem =="" || sotien ==""){
                    MSG(submitmsg);
                    return;
                }
                else{
                    var a = "../KhachHang_Controller?action=UpdateDoiDiem&sodiem="+sodiem+"&sotien="+sotien;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "success"){
                                MSG(msgdetail);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End Khách hàng

// Start thời điểm

function Time( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=40";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../ThoiDiem_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function AddTime(rightmsg, msgchecksubmit, msgdate){
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=41";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var timename = document.addTime.timename.value;
                var tugio = document.addTime.tugio.value;
                var tuphut = document.addTime.tuphut.value;
                var dengio = document.addTime.dengio.value;
                var denphut = document.addTime.denphut.value;
                if(timename == "" || tugio == "" || tuphut == "" || dengio =="" || denphut =="" ){
                    MSG(msgchecksubmit);
                    return;
                }
                else if(tugio >= 25 || dengio >= 25 || tuphut >= 61 || denphut >= 61){
                    MSG(msgdate);
                    return;
                }
                else{
                    var b = "../ThoiDiem_Controller?action=CheckTime&tugio="+tugio+"&tuphut="+tuphut+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:b,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var a = "../ThoiDiem_Controller?action=Add&timename="+timename+"&tugio="+tugio+"&tuphut="+tuphut+"&dengio="+dengio+"&denphut="+denphut;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        var aa = "../ThoiDiem_Controller?action=ShowTD&item=1";
                                        $.ajax({
                                            url:aa,
                                            dataType:"html",
                                            success:function(result){
                                                $("#DSTD").html(result);
                                            }
                                        });
                                        $("#timelang").html(result);
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                                return;
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function Edit_TD(mann, tentd, tugio, tuphut, dengio, denphut, hour, minutes) { // chuyển sang textbox để update    
    var a = "#tentd"+mann;
    var b = "#tugio"+mann;
    var c = "#tuphut"+mann;
    var d = "#dengio"+mann;
    var e = "#denphut"+mann;
    $(a).parent().html("<input type='textbox' class = 'text' style='width:140px' id="+a+" value='"+tentd+"'>");
    $(b).parent().html("<input type='textbox' class = 'text' maxlength = '2' onkeypress='return keypress(event)' style='width:35px;margin-left: 18px;' id="+b+" value='"+tugio+"'>   "+hour+"");
    $(c).parent().html("<input type='textbox' class = 'text' maxlength = '2' onkeypress='return keypress(event)' style='width:35px;margin-left: 18px;' id="+c+" value='"+tuphut+"'>   "+minutes+"");
    $(d).parent().html("<input type='textbox' class = 'text' maxlength = '2' onkeypress='return keypress(event)' style='width:35px;margin-left: 18px;' id="+d+" value='"+dengio+"'>   "+hour+"");
    $(e).parent().html("<input type='textbox' class = 'text' maxlength = '2' onkeypress='return keypress(event)' style='width:35px;margin-left: 18px;' id="+e+" value='"+denphut+"'>   "+minutes+"");

}
function Save_editTD( matd, mann, rightmsg, msgchecksubmit) {    // Update tên khu vực
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=42";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "#tentd"+mann;
                var b = "#tugio"+mann;
                var c = "#tuphut"+mann;
                var d = "#dengio"+mann;
                var e = "#denphut"+mann;
                var aa = document.getElementById(a);
                var bb = document.getElementById(b);
                var cc = document.getElementById(c);
                var dd = document.getElementById(d);
                var ee = document.getElementById(e);
                var tentd = aa.value;
                var tugio = bb.value;
                var tuphut = cc.value;
                var dengio = dd.value;
                var denphut = ee.value;
                if(tentd == "" || tugio == "" || tuphut == "" || dengio =="" || denphut =="" || tugio >= 25 || dengio >= 25 || tuphut >= 61 || denphut >= 61){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var x = "../ThoiDiem_Controller?action=Edit&tentd="+tentd+"&tugio="+tugio+"&tuphut="+tuphut+"&dengio="+dengio+"&denphut="+denphut+"&matd="+matd+"&mann="+mann;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            $("#timelang").html(result);
                            var y = "../ThoiDiem_Controller?action=ShowTD&item=1";
                            $.ajax({
                                url:y,
                                dataType:"html",
                                success:function(result){
                                    $("#DSTD").html(result);
                                }
                            });
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowLangTime(MaTD, rightmsg){  // Show detail khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=40";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../ThoiDiem_Controller?action=ShowLangTime&MaTD="+MaTD;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#timelang").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateStatusTime(status,  matd, rightmsg ){  // update tình trạng khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=42";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../ThoiDiem_Controller?action=UpdateStatusTime&matd="+matd+"&status="+status+"&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSTD").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchTime(item, rightmsg){ //Search khu vuc
    var c = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=40";
    $.ajax({
        url:c,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tentd = $('#searchTD .tentd').val();
                var tinhtrang = $('#searchTD .tinhtrang').val();
                var a = "../ThoiDiem_Controller?action=Search&tentd="+tentd+"&tinhtrang="+tinhtrang+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSTD").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenTD(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=40";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tentd";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../ThoiDiem_Controller?action=SortTenTD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../ThoiDiem_Controller?action=SortTenTD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTTD(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=40";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tttd";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../ThoiDiem_Controller?action=SortTTTD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../ThoiDiem_Controller?action=SortTTTD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenTD(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=40";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tentd = $('#searchTD .tentd').val();
                var tinhtrang = $('#searchTD .tinhtrang').val();
                var sortkv = "tentd";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../ThoiDiem_Controller?action=SortSearchTenTD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tentd="+tentd+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../ThoiDiem_Controller?action=SortSearchTenTD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tentd="+tentd+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTTD(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=40";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tentd = $('#searchTD .tentd').val();
                var tinhtrang = $('#searchTD .tinhtrang').val();
                var sortkv = "tttd";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../ThoiDiem_Controller?action=SortSearchTTTD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tentd="+tentd+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../ThoiDiem_Controller?action=SortSearchTTTD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tentd="+tentd+"&tinhtrang="+tinhtrang;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSTD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End thời điểm

// Start phí phục vụ

function ServiceCharge( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../PhiPV_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CreateSerCharge(rightmsg, msgchecksubmit, msgexist){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=44";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var makv = document.createsercharge.makv.value;
                var matd = document.createsercharge.matd.value;
                var servicecharge = document.createsercharge.servicecharge.value;
                if(servicecharge ==""){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var aa = "../PhiPV_Controller?action=Check&makv="+makv+"&matd="+matd;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            if(result == "exist"){
                                MSG(msgexist);
                            }
                            else{
                                var a = "../PhiPV_Controller?action=CreateSerCharge&makv="+makv+"&matd="+matd+"&servicecharge="+servicecharge;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        if(result == "success"){
                                            var aa = "../PhiPV_Controller?action=ShowDSPPV&item=1";
                                            $.ajax({
                                                url:aa,
                                                dataType:"html",
                                                success:function(result){
                                                    $("#DSPPV").html(result);
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenKVPPV(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){                
                var sortkv = "tenkv";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../PhiPV_Controller?action=SortTenKVPPV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../PhiPV_Controller?action=SortTenKVPPV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenTDPPV(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tentd";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../PhiPV_Controller?action=SortTenTDPPV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../PhiPV_Controller?action=SortTenTDPPV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortPPV(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ppv";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../PhiPV_Controller?action=SortPPV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../PhiPV_Controller?action=SortPPV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchSerCharge( item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchPPV .tenkv').val();
                var tentd = $('#searchPPV .tentd').val();
                var ppv = $('#searchPPV .ppv').val();
                var a = "../PhiPV_Controller?action=SearchSerCharge&tenkv="+tenkv+"&tentd="+tentd+"&ppv="+ppv+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DSPPV").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenKVPPV(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchPPV .tenkv').val();
                var tentd = $('#searchPPV .tentd').val();
                var ppv = $('#searchPPV .ppv').val();
                var sortkv = "tenkv";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../PhiPV_Controller?action=SortSearchTenKVPPV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tenkv="+tenkv+"&tentd="+tentd+"&ppv="+ppv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../PhiPV_Controller?action=SortSearchTenKVPPV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tenkv="+tenkv+"&tentd="+tentd+"&ppv="+ppv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenTDPPV(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchPPV .tenkv').val();
                var tentd = $('#searchPPV .tentd').val();
                var ppv = $('#searchPPV .ppv').val();
                var sortkv = "tenkv";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../PhiPV_Controller?action=SortSearchTenTDPPV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tenkv="+tenkv+"&tentd="+tentd+"&ppv="+ppv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../PhiPV_Controller?action=SortSearchTenTDPPV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tenkv="+tenkv+"&tentd="+tentd+"&ppv="+ppv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchPPV(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=43";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tenkv = $('#searchPPV .tenkv').val();
                var tentd = $('#searchPPV .tentd').val();
                var ppv = $('#searchPPV .ppv').val();
                var sortkv = "tenkv";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../PhiPV_Controller?action=SortSearchPPV&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tenkv="+tenkv+"&tentd="+tentd+"&ppv="+ppv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../PhiPV_Controller?action=SortSearchPPV&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tenkv="+tenkv+"&tentd="+tentd+"&ppv="+ppv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSPPV").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdatePPV(ppv, makv, matd, rightmsg, msgsuccess){  // update tình trạng khu vực
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=45";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../PhiPV_Controller?action=UpdatePPV&ppv="+ppv+"&makv="+makv+"&matd="+matd;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        if(result == "success"){
                            MSG(msgsuccess);
                            var aa = "../PhiPV_Controller?action=ShowDSPPV&item=1";
                            $.ajax({
                                url:aa,
                                dataType:"html",
                                success:function(result){
                                    $("#DSPPV").html(result);
                                }
                            });
                        }
                        
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End phí phục vụ

// Start lich su gia

function HistoryPrice(item, rightmsg) { // Show trang nhật ký
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../LSGia_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CheckAllLSG(){
    x = document.dslsg.total.value;
    if(x > 1){
        optionLSG = document.dslsg.optionLSG;
        for(i=0; i<optionLSG.length; i++)
        {
            if(!optionLSG[i].checked){
                optionLSG[i].click();
            }
        }
    }
    else{
        $('.optionLSG').click();
    }
}
function DeleteLSG(item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=47";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "";
                total = document.dslsg.total.value;
                if(total > 1){
                    optionLSG = document.dslsg.optionLSG;
                    for(i = 0; i < optionLSG.length; i++)
                    {
                        if(optionLSG[i].checked)
                        {
                            x =   x  + optionLSG[i].value + "-" ;
                        }
                    }
                }
                else{
                    if(document.dslsg.optionLSG.checked){
                        x = $('.optionLSG').val();
                    }
                }
                if(x == "") return;
                else{
                    var a = "../LSGia_Controller?action=DeleteLSG&malsg="+x+"&item="+item;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayGioLSG( sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchLSG .tungay').val();
                var tugio = $('#searchLSG .tugio').val();
                var tuphut = $('#searchLSG .tuphut').val();
                var denngay = $('#searchLSG .denngay').val();
                var dengio = $('#searchLSG .dengio').val();
                var denphut = $('#searchLSG .denphut').val();
                var tenmonan = $('#searchLSG .tenmonan').val();
                var tendvt = $('#searchLSG .tendvt').val();
                var gia = $('#searchLSG .gia').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "ngaygio";
                                if(sort == 'down'){
                                    $('#titledskv1 div.down1').removeClass('down1');
                                    $('#titledskv1 #sortkv1').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../LSGia_Controller?action=SortSearchNgayGioLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv1 div.up1').removeClass('up1');
                                    $('#titledskv1 #sortkv1').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../LSGia_Controller?action=SortSearchNgayGioLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchMonAnLSG( sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchLSG .tungay').val();
                var tugio = $('#searchLSG .tugio').val();
                var tuphut = $('#searchLSG .tuphut').val();
                var denngay = $('#searchLSG .denngay').val();
                var dengio = $('#searchLSG .dengio').val();
                var denphut = $('#searchLSG .denphut').val();
                var tenmonan = $('#searchLSG .tenmonan').val();
                var tendvt = $('#searchLSG .tendvt').val();
                var gia = $('#searchLSG .gia').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "monan";
                                if(sort == 'down'){
                                    $('#titledskv2 div.down1').removeClass('down1');
                                    $('#titledskv2 #sortkv2').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../LSGia_Controller?action=SortSearchMonAnLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv2 div.up1').removeClass('up1');
                                    $('#titledskv2 #sortkv2').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../LSGia_Controller?action=SortSearchMonAnLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchDVTLSG(sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchLSG .tungay').val();
                var tugio = $('#searchLSG .tugio').val();
                var tuphut = $('#searchLSG .tuphut').val();
                var denngay = $('#searchLSG .denngay').val();
                var dengio = $('#searchLSG .dengio').val();
                var denphut = $('#searchLSG .denphut').val();
                var tenmonan = $('#searchLSG .tenmonan').val();
                var tendvt = $('#searchLSG .tendvt').val();
                var gia = $('#searchLSG .gia').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "dvt";
                                if(sort == 'down'){
                                    $('#titledskv3 div.down1').removeClass('down1');
                                    $('#titledskv3 #sortkv3').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../LSGia_Controller?action=SortSearchDVTLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv3 div.up1').removeClass('up1');
                                    $('#titledskv3 #sortkv3').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../LSGia_Controller?action=SortSearchDVTLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
                
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchGiaLSG( sort, item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchLSG .tungay').val();
                var tugio = $('#searchLSG .tugio').val();
                var tuphut = $('#searchLSG .tuphut').val();
                var denngay = $('#searchLSG .denngay').val();
                var dengio = $('#searchLSG .dengio').val();
                var denphut = $('#searchLSG .denphut').val();
                var tenmonan = $('#searchLSG .tenmonan').val();
                var tendvt = $('#searchLSG .tendvt').val();
                var gia = $('#searchLSG .gia').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "gia";
                                if(sort == 'down'){
                                    $('#titledskv4 div.down2').removeClass('down2');
                                    $('#titledskv4 #sortkv4').addClass('up2');
                                    var order1 = "asc";
                                    var a = "../LSGia_Controller?action=SortSearchGiaLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv4 div.up2').removeClass('up2');
                                    $('#titledskv4 #sortkv4').addClass('down2');
                                    var order2 = "desc";
                                    var aa = "../LSGia_Controller?action=SortSearchGiaLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSLSG").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchLSG(item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchLSG .tungay').val();
                var tugio = $('#searchLSG .tugio').val();
                var tuphut = $('#searchLSG .tuphut').val();
                var denngay = $('#searchLSG .denngay').val();
                var dengio = $('#searchLSG .dengio').val();
                var denphut = $('#searchLSG .denphut').val();
                var tenmonan = $('#searchLSG .tenmonan').val();
                var tendvt = $('#searchLSG .tendvt').val();
                var gia = $('#searchLSG .gia').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var a = "../LSGia_Controller?action=SearchLSG&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&tenmonan="+tenmonan+"&tendvt="+tendvt+"&gia="+gia+"&item="+item;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSLSG").html(result);
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }

            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayGioLSG( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../LSGia_Controller?action=SortNgayGioLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LSGia_Controller?action=SortNgayGioLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortMonAnLSG( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "monan";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../LSGia_Controller?action=SortMonAnLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LSGia_Controller?action=SortMonAnLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortDVTLSG(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "dvt";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../LSGia_Controller?action=SortDVTLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../LSGia_Controller?action=SortDVTLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortGiaLSG( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=46";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "gia";
                if(sort == 'down'){
                    $('#titledskv4 div.down2').removeClass('down2');
                    $('#titledskv4 #sortkv4').addClass('up2');
                    var order1 = "asc";
                    var a = "../LSGia_Controller?action=SortGiaLSG&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up2').removeClass('up2');
                    $('#titledskv4 #sortkv4').addClass('down2');
                    var order2 = "desc";
                    var aa = "../LSGia_Controller?action=SortGiaLSG&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSLSG").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End lich su gia

// Start Dat ban

function Reservation(item, rightmsg) {    
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var aa = "DatBan_Controller?action=ShowDB&item="+item;
                $.ajax({
                    url:aa,
                    dataType:"html",
                    success:function(result){
                        $("#DSDB").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowMapReserv(makv, item, rightmsg){   // Hiển thị sơ đồ bàn
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "DatBan_Controller?action=Map&makv="+makv+"&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){                        
                        $("#Map").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchSeat(soghe, makv, item, rightmsg){   // Hiển thị sơ đồ bàn
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){                
                var a = "";
                if(soghe == ""){
                    a = "DatBan_Controller?action=SearchSeat&soghe=all&makv="+makv+"&item="+item;
                }
                else{
                    a = "DatBan_Controller?action=SearchSeat&soghe="+soghe+"&makv="+makv+"&item="+item;
                }                
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#Map").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ClickSearchSeat(){
    document.seat.searchseat.value = "";
}
function CreateReserv(rightmsg, msgchecksubmit, msgcheckreserv) { // Tạo bàn
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=49";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var makv = document.addReserv.makv.value;
                var tenban = document.addReserv.tenban.value;
                var tenkh = document.addReserv.tenkh.value;
                var sokhach = document.addReserv.sokhach.value;
                var ngay = document.addReserv.ngay.value;
                var gio = document.addReserv.gio.value;
                var sodt = document.addReserv.sodt.value;
                if(makv == "" || tenban == "" || tenkh == "" || sokhach == "" || ngay == "" || gio == "" || sodt == "" || gio >= 25){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var b = "DatBan_Controller?action=CheckBan&makv="+makv+"&tenban="+tenban;
                    $.ajax({
                        url:b,
                        dataType:"html",
                        success:function(result){
                            if(result != "exist"){
                                MSG(msgchecksubmit);
                            }
                            else{
                                var aa = "DatBan_Controller?action=CheckDatBan&makv="+makv+"&tenban="+tenban+"&ngay="+ngay+"&gio="+gio;
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        if(result == "false"){
                                            MSG(msgcheckreserv)
                                        }
                                        else{
                                            var a = "DatBan_Controller?action=Add&makv="+makv+"&tenban="+tenban+"&tenkh="+tenkh+"&sokhach="+sokhach+"&ngay="+ngay+"&gio="+gio+"&sodt="+sodt;
                                            $.ajax({
                                                url:a,
                                                dataType:"html",
                                                success:function(result){
                                                    var a = "DatBan_Controller?action=Map&makv="+makv+"&item=1";
                                                    $.ajax({
                                                        url:a,
                                                        dataType:"html",
                                                        success:function(result){
                                                            $("#Map").html(result);
                                                            var aa = "DatBan_Controller?action=ShowDB&item=1&makv="+makv;
                                                            $.ajax({
                                                                url:aa,
                                                                dataType:"html",
                                                                success:function(result){
                                                                    $("#DSDB").html(result);
                                                                }
                                                            });
                                                        }
                                                    });                                                    
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });                    
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowDatBan(maban, tenban, makv){   // Hiển thị sơ đồ bàn
    document.addReserv.tenban.value = tenban;
    var a = "DatBan_Controller?action=ShowDatBan&maban="+maban+"&item=1&makv="+makv;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){            
            $("#DSDB").html(result);
        }
    });
}
function CheckAllDB(){
    x = document.dsdb.total.value;
    if(x > 1){
        optionDB = document.dsdb.optionDB;
        for(i=0; i<optionDB.length; i++)
        {
            if(!optionDB[i].checked){
                optionDB[i].click();
            }
        }
    }
    else{
        $('.optionDB').click();
    }
}
function DeleteDB( item, rightmsg){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=51";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "";
                total = document.dsdb.total.value;
                if(total > 1){
                    optionDB = document.dsdb.optionDB;
                    for(i = 0; i < optionDB.length; i++)
                    {
                        if(optionDB[i].checked)
                        {
                            x =   x  + optionDB[i].value + "-" ;
                        }
                    }
                }
                else{
                    if(document.dsdb.optionDB.checked){
                        x = $('.optionDB').val();
                    }
                }
                if(x == "") return;
                else{
                    var a = "DatBan_Controller?action=DeleteDB&madb="+x+"&item="+item;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function DetailDB(rightmsg, madb , maban){   // Hiển thị sơ đồ bàn
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "DatBan_Controller?action=DetailDB&madb="+madb+"&maban="+maban;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#createDB").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateReserv(madb, rightmsg, msgchecksubmit, msgdetail, msgcheckreserv) { 
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=50";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var makv = document.addReserv.makv.value;
                var tenban = document.addReserv.tenban.value;
                var tenkh = document.addReserv.tenkh.value;
                var sokhach = document.addReserv.sokhach.value;
                var ngay = document.addReserv.ngay.value;
                var gio = document.addReserv.gio.value;
                var sodt = document.addReserv.sodt.value;
                if(makv == "" || tenban == "" || tenkh == "" || sokhach == "" || ngay == "" || gio == "" || sodt == "" || gio >= 25){
                    MSG(msgchecksubmit);
                    return;
                }
                else{
                    var b = "DatBan_Controller?action=CheckBan&makv="+makv+"&tenban="+tenban;
                    $.ajax({
                        url:b,
                        dataType:"html",
                        success:function(result){
                            if(result != "exist"){
                                MSG(msgchecksubmit);
                            }
                            else{
                                var aa = "DatBan_Controller?action=CheckDatBanUpdate&makv="+makv+"&tenban="+tenban+"&ngay="+ngay+"&gio="+gio+"&madb="+madb;
                                $.ajax({
                                    url:aa,
                                    dataType:"html",
                                    success:function(result){
                                        if(result == "false"){
                                            MSG(msgcheckreserv)
                                        }
                                        else{
                                            var a = "DatBan_Controller?action=UpdateReserv&makv="+makv+"&tenban="+tenban+"&tenkh="+tenkh+"&sokhach="+sokhach+"&ngay="+ngay+"&gio="+gio+"&sodt="+sodt+"&madb="+madb;
                                            $.ajax({
                                                url:a,
                                                dataType:"html",
                                                success:function(result){
                                                    MSG(msgdetail);
                                                    var a = "DatBan_Controller?action=Map&makv="+makv+"&item=1";
                                                    $.ajax({
                                                        url:a,
                                                        dataType:"html",
                                                        success:function(result){
                                                            $("#Map").html(result);
                                                            var aa = "DatBan_Controller?action=ShowDB&item=1";
                                                            $.ajax({
                                                                url:aa,
                                                                dataType:"html",
                                                                success:function(result){
                                                                    $("#DSDB").html(result);
                                                                }
                                                            });
                                                        }
                                                    });
                                                    
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });

                }

            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchDB(item, rightmsg, msgdate){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchDB .tungay').val();
                var tugio = $('#searchDB .tugio').val();
                var denngay = $('#searchDB .denngay').val();
                var dengio = $('#searchDB .dengio').val();
                var tenkv = $('#searchDB .tenkv').val();
                var tenban = $('#searchDB .tenban').val();
                var kh = $('#searchDB .kh').val();
                var sodt = $('#searchDB .sodt').val();
                var sokhach = $('#searchDB .sokhach').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" ||  dengio == "" ){
                    MSG(msgdate);
                }
                else{
                    var x = "DatBan_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var a = "DatBan_Controller?action=SearchDB&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach+"&item="+item;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSDB").html(result);
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayGioDB( sort, item, rightmsg, msgdate){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchDB .tungay').val();
                var tugio = $('#searchDB .tugio').val();
                var denngay = $('#searchDB .denngay').val();
                var dengio = $('#searchDB .dengio').val();
                var tenkv = $('#searchDB .tenkv').val();
                var tenban = $('#searchDB .tenban').val();
                var kh = $('#searchDB .kh').val();
                var sodt = $('#searchDB .sodt').val();
                var sokhach = $('#searchDB .sokhach').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" ||  dengio == "" ){
                    MSG(msgdate);
                }
                else{
                    var x = "DatBan_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "ngaygio";
                                if(sort == 'down'){
                                    $('#titledskv1 div.down1').removeClass('down1');
                                    $('#titledskv1 #sortkv1').addClass('up1');
                                    var order1 = "asc";
                                    var a = "DatBan_Controller?action=SortSearchNgayGioDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv1 div.up1').removeClass('up1');
                                    $('#titledskv1 #sortkv1').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "DatBan_Controller?action=SortSearchNgayGioDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchKVDB( sort, item, rightmsg, msgdate){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchDB .tungay').val();
                var tugio = $('#searchDB .tugio').val();
                var denngay = $('#searchDB .denngay').val();
                var dengio = $('#searchDB .dengio').val();
                var tenkv = $('#searchDB .tenkv').val();
                var tenban = $('#searchDB .tenban').val();
                var kh = $('#searchDB .kh').val();
                var sodt = $('#searchDB .sodt').val();
                var sokhach = $('#searchDB .sokhach').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" ||  dengio == "" ){
                    MSG(msgdate);
                }
                else{
                    var x = "DatBan_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "kv";
                                if(sort == 'down'){
                                    $('#titledskv2 div.down1').removeClass('down1');
                                    $('#titledskv2 #sortkv2').addClass('up1');
                                    var order1 = "asc";
                                    var a = "DatBan_Controller?action=SortSearchKVDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv2 div.up1').removeClass('up1');
                                    $('#titledskv2 #sortkv2').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "DatBan_Controller?action=SortSearchKVDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTenBanDB( sort, item, rightmsg, msgdate){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchDB .tungay').val();
                var tugio = $('#searchDB .tugio').val();
                var denngay = $('#searchDB .denngay').val();
                var dengio = $('#searchDB .dengio').val();
                var tenkv = $('#searchDB .tenkv').val();
                var tenban = $('#searchDB .tenban').val();
                var kh = $('#searchDB .kh').val();
                var sodt = $('#searchDB .sodt').val();
                var sokhach = $('#searchDB .sokhach').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" ||  dengio == "" ){
                    MSG(msgdate);
                }
                else{
                    var x = "DatBan_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "tenban";
                                if(sort == 'down'){
                                    $('#titledskv3 div.down1').removeClass('down1');
                                    $('#titledskv3 #sortkv3').addClass('up1');
                                    var order1 = "asc";
                                    var a = "DatBan_Controller?action=SortSearchTenBanDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv3 div.up1').removeClass('up1');
                                    $('#titledskv3 #sortkv3').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "DatBan_Controller?action=SortSearchTenBanDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }                
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchKHDB( sort, item, rightmsg, msgdate){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchDB .tungay').val();
                var tugio = $('#searchDB .tugio').val();
                var denngay = $('#searchDB .denngay').val();
                var dengio = $('#searchDB .dengio').val();
                var tenkv = $('#searchDB .tenkv').val();
                var tenban = $('#searchDB .tenban').val();
                var kh = $('#searchDB .kh').val();
                var sodt = $('#searchDB .sodt').val();
                var sokhach = $('#searchDB .sokhach').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" ||  dengio == "" ){
                    MSG(msgdate);
                }
                else{
                    var x = "DatBan_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "kh";
                                if(sort == 'down'){
                                    $('#titledskv4 div.down1').removeClass('down1');
                                    $('#titledskv4 #sortkv4').addClass('up1');
                                    var order1 = "asc";
                                    var a = "DatBan_Controller?action=SortSearchKHDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv4 div.up1').removeClass('up1');
                                    $('#titledskv4 #sortkv4').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "DatBan_Controller?action=SortSearchKHDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchDTDB( sort, item, rightmsg, msgdate){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchDB .tungay').val();
                var tugio = $('#searchDB .tugio').val();
                var denngay = $('#searchDB .denngay').val();
                var dengio = $('#searchDB .dengio').val();
                var tenkv = $('#searchDB .tenkv').val();
                var tenban = $('#searchDB .tenban').val();
                var kh = $('#searchDB .kh').val();
                var sodt = $('#searchDB .sodt').val();
                var sokhach = $('#searchDB .sokhach').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" ||  dengio == "" ){
                    MSG(msgdate);
                }
                else{
                    var x = "DatBan_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "dt";
                                if(sort == 'down'){
                                    $('#titledskv5 div.down1').removeClass('down1');
                                    $('#titledskv5 #sortkv5').addClass('up1');
                                    var order1 = "asc";
                                    var a = "DatBan_Controller?action=SortSearchDTDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv5 div.up1').removeClass('up1');
                                    $('#titledskv5 #sortkv5').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "DatBan_Controller?action=SortSearchDTDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }                
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchSoKhachDB( sort, item, rightmsg, msgdate){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchDB .tungay').val();
                var tugio = $('#searchDB .tugio').val();
                var denngay = $('#searchDB .denngay').val();
                var dengio = $('#searchDB .dengio').val();
                var tenkv = $('#searchDB .tenkv').val();
                var tenban = $('#searchDB .tenban').val();
                var kh = $('#searchDB .kh').val();
                var sodt = $('#searchDB .sodt').val();
                var sokhach = $('#searchDB .sokhach').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" ||  dengio == "" ){
                    MSG(msgdate);
                }
                else{
                    var x = "DatBan_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "sokhach";
                                if(sort == 'down'){
                                    $('#titledskv6 div.down2').removeClass('down2');
                                    $('#titledskv6 #sortkv6').addClass('up2');
                                    var order1 = "asc";
                                    var a = "DatBan_Controller?action=SortSearchSoKhachDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv6 div.up2').removeClass('up2');
                                    $('#titledskv6 #sortkv6').addClass('down2');
                                    var order2 = "desc";
                                    var aa = "DatBan_Controller?action=SortSearchSoKhachDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&denngay="+denngay+"&dengio="+dengio+"&tenkv="+tenkv+"&tenban="+tenban+"&kh="+kh+"&sodt="+sodt+"&sokhach="+sokhach;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSDB").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }                
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayGioDB( sort, item, rightmsg){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "DatBan_Controller?action=SortNgayGioDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "DatBan_Controller?action=SortNgayGioDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortKVDB( sort, item, rightmsg){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "kv";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "DatBan_Controller?action=SortKVDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "DatBan_Controller?action=SortKVDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTenBanDB( sort, item, rightmsg){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tenban";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "DatBan_Controller?action=SortTenBanDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "DatBan_Controller?action=SortTenBanDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortKHDB( sort, item, rightmsg){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "kh";
                if(sort == 'down'){
                    $('#titledskv4 div.down1').removeClass('down1');
                    $('#titledskv4 #sortkv4').addClass('up1');
                    var order1 = "asc";
                    var a = "DatBan_Controller?action=SortKHDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up1').removeClass('up1');
                    $('#titledskv4 #sortkv4').addClass('down1');
                    var order2 = "desc";
                    var aa = "DatBan_Controller?action=SortKHDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortDTDB( sort, item, rightmsg){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "dt";
                if(sort == 'down'){
                    $('#titledskv5 div.down1').removeClass('down1');
                    $('#titledskv5 #sortkv5').addClass('up1');
                    var order1 = "asc";
                    var a = "DatBan_Controller?action=SortDTDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv5 div.up1').removeClass('up1');
                    $('#titledskv5 #sortkv5').addClass('down1');
                    var order2 = "desc";
                    var aa = "DatBan_Controller?action=SortDTDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSoKhachDB( sort, item, rightmsg){
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=48";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "sokhach";
                if(sort == 'down'){
                    $('#titledskv6 div.down2').removeClass('down2');
                    $('#titledskv6 #sortkv6').addClass('up2');
                    var order1 = "asc";
                    var a = "DatBan_Controller?action=SortSoKhachDB&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv6 div.up2').removeClass('up2');
                    $('#titledskv6 #sortkv6').addClass('down2');
                    var order2 = "desc";
                    var aa = "DatBan_Controller?action=SortSoKhachDB&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSDB").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End dat ban

// Phieu dat mon an

function Orderbill() {
    $("#notification").html("<img alt='' src='images/notification.png'>");    
}
function Orderbill1() {
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=52";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "PhieuDatMA_Controller?action=ShowOrderbill&item=1";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#notification").html("<img alt='' src='images/notification.png'>");
                        $("#DSBanTT").html(result);
                    }
                });
            }
        }
    });
}
function DetailDMA(maban, rightmsg){
    
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=52";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "PhieuDatMA_Controller?action=Detail&maban="+maban;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#DMA").show();
                        $("#DMA").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
    
}
function Notification(){    // Show detail bàn
    var a = "../PhieuDatMA_Controller?action=Notification";
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#notification").html(result);
        }
    });
}
function Notification1(){    // Show detail bàn
    var a = "PhieuDatMA_Controller?action=Notification1";
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#notification").html(result);
        }
    });
}
function UpdatePDMA(maban, makh,  sohdt, rightmsg, checksubmitmsg ){    
    var b = "NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=54";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "PhieuDatMA_Controller?action=CheckKHExist&makh="+makh;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        if(result == "true"){
                            var a = "PhieuDatMA_Controller?action=UpdatePDMA&makh="+makh+"&sohdt="+sohdt+"&maban="+maban;
                            $.ajax({
                                url:a,
                                dataType:"html",
                                success:function(result){
                                    $("#DMA").html(result);
                                }
                            });
                        }
                        else{
                            MSG(checksubmitmsg);                            
                            document.getElementById("customerid").value = "0";
                            $("#tenkh").html("");
                        }
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function LayTienThoiLai(tienkhach, tamtinh, checksubmitmsg){
    if(tienkhach == ""){
        MSG(checksubmitmsg);
    }
    else{
        var a = "PhieuDatMA_Controller?action=CheckTien&tamtinh="+tamtinh+"&tienkhach="+tienkhach;
        $.ajax({
            url:a,
            dataType:"html",
            success:function(result){
                
                if(result == "true"){
                    var a = "PhieuDatMA_Controller?action=LayTienThoiLai&tienkhach="+tienkhach+"&tamtinh="+tamtinh;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#tienthoilai").html(result);
                        }
                    });
                }
                else{
                    document.DMAinfo.tienkhach.value = "";
                    MSG(checksubmitmsg);
                }
            }
        });
    }
}
function InHoaDon(maban, sohdt, rightmsg, checksubmitmsg){    
    var tienkhach = document.DMAinfo.tienkhach.value;
    if(tienkhach == ""){
        MSG(checksubmitmsg);
    }
    else{
        var f = document.getElementById("PDMAinfo");
        f.action = "PhieuDatMA_Controller?action=InHoaDon&sohdt="+sohdt+"&tienkhach="+tienkhach+"&maban="+maban;
        f.submit();
        $('#DMA').hide();
    }   
}
function InPDMA(sohdt, maban){
    var f = document.getElementById("PDMAinfo");
    f.action = "PhieuDatMA_Controller?action=InPDMA&sohdt="+sohdt+"&maban="+maban;
    f.submit();
}
// End phieu dat mon an

// Start thống kê

function Statistics(item, rightmsg) { // Show trang nhật ký 
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=64";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../ThongKe_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowDKLoc(loaithongke, rightmsg) { // Show trang nhật ký
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../ThongKe_Controller?action=ShowDKLoc&loaithongke="+loaithongke;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#dieukienloc").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CheckDateStatics(){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=7";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var ngaybd = $('#dieukienloc .ngaybd').val();
                var ngaykt = $('#dieukienloc .ngaykt').val();
                if(ngaybd != "" && ngaykt != ""){
                    var a = "../ThongKe_Controller?action=CheckDate&ngaybd="+ngaybd+"&ngaykt="+ngaykt;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                document.getElementById("submitstatics").value = "true";
                            }
                            else{
                                document.getElementById("submitstatics").value = "false";
                            }
                        }
                    });
                }
            }
            else{
                document.getElementById("submitstatics").value = "false";
            }
        }
    });
}
function LapBaoCao(rightmsg, msgdate, item) {
    var submitstatics = document.getElementById("submitstatics").value;
    var chkchart = document.getElementById("chkchart");
    if(submitstatics == "true"){
        var f = document.getElementById("frmcook");
        var loaithongke = $('#loaithongke').val();
        var ngaybd = $('#dieukienloc .ngaybd').val();
        var ngaykt = $('#dieukienloc .ngaykt').val();
        if(ngaybd != "" && ngaykt == ""){
            MSG(msgdate);
        }
        else if(ngaybd == "" && ngaykt != ""){
            MSG(msgdate);
        }
        else{
            if(loaithongke == "turnoverfood"){                
                f.action = "../ThongKe_Controller?action=Turnoverfood";
            }
            else if(loaithongke == "turnoveruser"){                
                f.action = "../ThongKe_Controller?action=Turnoveruser";
            }
            else if(loaithongke == "turnoverarea"){                
                f.action = "../ThongKe_Controller?action=Turnoverarea";
            }
            else if(loaithongke == "turnoverbill"){                
                f.action = "../ThongKe_Controller?action=Turnoverbill";
            }
            else if(loaithongke == "turnovercustomer"){                
                f.action = "../ThongKe_Controller?action=Turnovercustomer";
            }
            else if(loaithongke == "topfood"){                
                f.action = "../ThongKe_Controller?action=Topfood";
            }
            else if(loaithongke == "chartturnoverr"){
                f.action = "../ThongKe_Controller?action=Chartturnoverr";
            }
            else{                
                f.action = "../ThongKe_Controller?action=Toptable";
            }
        }    
    }
    else{
        
        MSG(msgdate);
    }    
    f.submit();        
}   


// End thống kê

// Start đầu bếp

function Cook(){    
    var a = "../DauBep_Controller?action=Show";    
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#rscook").html(result);            
        }
    });
}
function CookInteval(){
    var ng = document.getElementById("SortNgayGioCook").value;
    var kv = document.getElementById("SortKVCook").value;
    var b = document.getElementById("SortBanCook").value;
    var ma = document.getElementById("SortMACook").value;
    var dvt = document.getElementById("SortDVTCook").value;
    var sl = document.getElementById("SortSLCook").value;
    var ud1 = document.getElementById("SortNgayGioCook").alt;
    var ud2 = document.getElementById("SortKVCook").alt;
    var ud3 = document.getElementById("SortBanCook").alt;
    var ud4 = document.getElementById("SortMACook").alt;
    var ud5 = document.getElementById("SortDVTCook").alt;
    var ud6 = document.getElementById("SortSLCook").alt;
    var makv = $('#searchCook .makv').val();
    var tenban = $('#searchCook .tenban').val();
    var tenma = $('#searchCook .tenma').val();
    var tendvt = $('#searchCook .tendvt').val();
    var soluong = $('#searchCook .soluong').val();
    var mattma = $('#searchCook .mattma').val();
    var a = "../DauBep_Controller?action=CookInteval&ng="+ng+"&kv="+kv+"&b="+b+"&ma="+ma+"&dvt="+dvt+"&sl="+sl+"&ud1="+ud1+"&ud2="+ud2+"&ud3="+ud3+"&ud4="+ud4+"&ud5="+ud5+"&ud6="+ud6+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#rscook").html(result);
        }
    });
}
function Refresh(){    // Show detail bàn
    if(idd != null){
        clearInterval(idd);
        idd = null;
    }
    if(id != null){
        clearInterval(id);
        id = null;
    }
    if(ht != null){
        clearInterval(ht);
        ht = null;
    }
    if(id == null){
        Cook();
        id = setInterval( "Cook()", 3000 );
    }
}
function Cook3(){    // Show detail bàn
    var a = "../DauBep_Controller?action=Show3";
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#rscook").html(result);

        }
    });
}

function DSHoiThuc(){
    var count = document.getElementById("layht").value;
    if(count == "0"){
        clearInterval(ht);
        ht = null;
        id = setInterval( "Cook()", 2000 );
    }
    var a = "../DauBep_Controller?action=DSHoiThuc";
    $.ajax({
        url:a,
        dataType:"html",
        success:function(result){
            $("#rshoithuc").html(result);
            var b = "../DauBep_Controller?action=CountDSHoiThuc";
            $.ajax({
                url:b,
                dataType:"html",
                success:function(result){
                    $(".hoithuc").html(result);
                    
                }
            });
        }
    });
    
}
function CheckboxCook(){
    clearInterval(id);
    id = null;
}
function CheckboxCookHT(){
    clearInterval(ht);
    ht = null;
}
function CheckboxCook3(){
    clearInterval(idd);
    idd = null;
}
function ShowHoiThuc(){
    //    var count = document.getElementById("layht").value;
    //    if(count == "0"){
    //        clearInterval(ht);
    //        ht = null;
    //        clearInterval(id);
    //        id = null;
    //        id = setInterval( "Cook()", 2000 );
    //    }
    //    else{
    if($('#rshoithuc').is(':hidden')==true){
        $('#rshoithuc').slideDown('medium');
        clearInterval(id);
        id = null;
        ht = setInterval( "DSHoiThuc()", 2000 );
    }
    else{
        $('#rshoithuc').slideUp('medium');
        clearInterval(ht);
        ht = null;
        id = setInterval( "Cook()", 2000 );
    }
//    }
}

function ShowHoiThucHT(){
    clearInterval(idd);
    idd = null;
    $('#rshoithuc:visible').slideUp('medium');
    if($('#rshoithuc').is(':hidden')==true){
        $('#rshoithuc').slideDown('medium');
    }
}

function UpdateTTMACook(MaCTHDT, MaTTMA, rightmsg) {
    if(ht != null){
        clearInterval(ht);
        ht = null;
        id = setInterval( "Cook()", 2000 );
    }
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=58";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../DauBep_Controller?action=UpdateTTMACook&MaCTHDT="+MaCTHDT+"&MaTTMA="+MaTTMA;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#rscook").html(result);                        
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });      
}
function BoQuaHoiThuc(MaCTHDT, rightmsg) {
    clearInterval(ht);
    ht = null;
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=58";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../DauBep_Controller?action=BoQuaHoiThuc&MaCTHDT="+MaCTHDT;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        //$("#rscook").html(result);
                        
                        id = setInterval( "Cook()", 2000 );
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateTTMACook3(MaCTHDT, MaTTMA, rightmsg) {
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=58";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../DauBep_Controller?action=UpdateTTMACook3&MaCTHDT="+MaCTHDT+"&MaTTMA="+MaTTMA;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#rscook").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}

function UpdateTTCook(TT, MaMA, rightmsg, MaCTHDT) {
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=58";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){                
                var a = "../DauBep_Controller?action=UpdateTTCook&TT="+TT+"&MaMA="+MaMA+"&MaCTHDT="+MaCTHDT;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#rscook").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayGioCook(sort, item, rightmsg){    
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortNgayGioCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortNgayGioCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
    
}
function SortNgayGioCook3(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortNgayGioCook3&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortNgayGioCook3&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });

}
function SortKVCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortKVCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortKVCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortKVCook3(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortKVCook3&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortKVCook3&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortBanCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortBanCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortBanCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortBanCook3(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortBanCook3&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortBanCook3&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortMACook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv4 div.down1').removeClass('down1');
                    $('#titledskv4 #sortkv4').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortMACook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up1').removeClass('up1');
                    $('#titledskv4 #sortkv4').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortMACook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortMACook3(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv4 div.down1').removeClass('down1');
                    $('#titledskv4 #sortkv4').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortMACook3&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up1').removeClass('up1');
                    $('#titledskv4 #sortkv4').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortMACook3&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortDVTCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv5 div.down1').removeClass('down1');
                    $('#titledskv5 #sortkv5').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortDVTCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv5 div.up1').removeClass('up1');
                    $('#titledskv5 #sortkv5').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortDVTCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortDVTCook3(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv5 div.down1').removeClass('down1');
                    $('#titledskv5 #sortkv5').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortDVTCook3&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv5 div.up1').removeClass('up1');
                    $('#titledskv5 #sortkv5').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortDVTCook3&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSLCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv6 div.down1').removeClass('down1');
                    $('#titledskv6 #sortkv6').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSLCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv6 div.up1').removeClass('up1');
                    $('#titledskv6 #sortkv6').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSLCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSLCook3(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv6 div.down1').removeClass('down1');
                    $('#titledskv6 #sortkv6').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSLCook3&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv6 div.up1').removeClass('up1');
                    $('#titledskv6 #sortkv6').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSLCook3&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv8 div.down1').removeClass('down1');
                    $('#titledskv8 #sortkv8').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortTTCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv8 div.up1').removeClass('up1');
                    $('#titledskv8 #sortkv8').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortTTCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTTCook3(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv8 div.down1').removeClass('down1');
                    $('#titledskv8 #sortkv8').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortTTCook3&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv8 div.up1').removeClass('up1');
                    $('#titledskv8 #sortkv8').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortTTCook3&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchCook(rightmsg){ //Search khu vuc
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                var a = "../DauBep_Controller?action=SearchCook&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#rscook").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayGioCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSearchNgayGioCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSearchNgayGioCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });

}
function SortSearchKVCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSearchKVCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSearchKVCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchBanCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSearchBanCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSearchBanCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchMACook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                if(sort == 'down'){
                    $('#titledskv4 div.down1').removeClass('down1');
                    $('#titledskv4 #sortkv4').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSearchMACook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up1').removeClass('up1');
                    $('#titledskv4 #sortkv4').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSearchMACook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchDVTCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                if(sort == 'down'){
                    $('#titledskv5 div.down1').removeClass('down1');
                    $('#titledskv5 #sortkv5').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSearchDVTCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv5 div.up1').removeClass('up1');
                    $('#titledskv5 #sortkv5').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSearchDVTCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchSLCook(sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                if(sort == 'down'){
                    $('#titledskv6 div.down1').removeClass('down1');
                    $('#titledskv6 #sortkv6').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSearchSLCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv6 div.up1').removeClass('up1');
                    $('#titledskv6 #sortkv6').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSearchSLCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTTCook(sort, item, rightmsg){ 
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=57";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                var makv = $('#searchCook .makv').val();
                var tenban = $('#searchCook .tenban').val();
                var tenma = $('#searchCook .tenma').val();
                var tendvt = $('#searchCook .tendvt').val();
                var soluong = $('#searchCook .soluong').val();
                var mattma = $('#searchCook .mattma').val();
                if(sort == 'down'){
                    $('#titledskv8 div.down1').removeClass('down1');
                    $('#titledskv8 #sortkv8').addClass('up1');
                    var order1 = "asc";
                    var a = "../DauBep_Controller?action=SortSearchTTCook&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv8 div.up1').removeClass('up1');
                    $('#titledskv8 #sortkv8').addClass('down1');
                    var order2 = "desc";
                    var aa = "../DauBep_Controller?action=SortSearchTTCook&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&makv="+makv+"&tenban="+tenban+"&tenma="+tenma+"&tendvt="+tendvt+"&soluong="+soluong+"&mattma="+mattma;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#rscook").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function InPhieuCook(rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=69";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var count = document.getElementById("total").value;
                var MaCTHDT = "";
                var MaMA = "";
                var SL = "";
                var DVT = "";
                var GC = "";
                if(count > 1){
                    chkcook = document.frmcookk.chkcook;
                    for(i = 0; i < chkcook.length; i++)
                    {
                        if(chkcook[i].checked)
                        {
                            MaCTHDT = MaCTHDT + chkcook[i].className + ";" ;
                            MaMA = MaMA + chkcook[i].value + ";" ;
                            SL = SL + chkcook[i].alt + ";" ;
                            DVT = DVT + chkcook[i].id + ";" ;
                            GC = GC + chkcook[i].lang + ";" ;
                        }
                    }
                }
                else{
                    if(document.frmcookk.chkcook.checked){
                        MaCTHDT = document.frmcookk.chkcook.className;
                        MaMA = document.frmcookk.chkcook.value;
                        SL = document.frmcookk.chkcook.alt;
                        DVT = document.frmcookk.chkcook.id;
                        GC = document.frmcookk.chkcook.lang;
                    }
                }
                if(MaCTHDT != ""){
                    var a = "../DauBep_Controller?action=InPhieuCook&MaMA="+MaMA+"&SL="+SL+"&DVT="+DVT+"&GC="+GC+"&MaCTHDT="+MaCTHDT;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#mbcook").html(result);
                        }
                    });
                    $('#mbcook').modal({
                        close:false,
                        closeHTML:null,
                        overlayClose:false
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}

function PhanCongHT(rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=69";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var count = document.getElementById("totalht").value;
                var MaCTHDT = "";
                var MaMA = "";
                var SL = "";
                var DVT = "";
                var GC = "";
                if(count > 1){
                    chkcookht = document.frmcookk.chkcookht;
                    for(i = 0; i < chkcookht.length; i++)
                    {
                        if(chkcookht[i].checked)
                        {
                            MaCTHDT = MaCTHDT + chkcookht[i].className + ";" ;
                            MaMA = MaMA + chkcookht[i].value + ";" ;
                            SL = SL + chkcookht[i].alt + ";" ;
                            DVT = DVT + chkcookht[i].id + ";" ;
                            GC = GC + chkcookht[i].lang + ";" ;
                        }
                    }
                }
                else{
                    if(document.frmcookk.chkcookht.checked){
                        MaCTHDT = document.frmcookk.chkcookht.className;
                        MaMA = document.frmcookk.chkcookht.value;
                        SL = document.frmcookk.chkcookht.alt;
                        DVT = document.frmcookk.chkcookht.id;
                        GC = document.frmcookk.chkcookht.lang;
                    }
                }
                if(MaCTHDT != ""){
                    var a = "../DauBep_Controller?action=InPhieuCook&MaMA="+MaMA+"&SL="+SL+"&DVT="+DVT+"&GC="+GC+"&MaCTHDT="+MaCTHDT;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#mbcook").html(result);
                        }
                    });
                    $('#mbcook').modal({
                        close:false,
                        closeHTML:null,
                        overlayClose:false
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function PhanCongMA(chefmsg){
    var manv = document.getElementById("manv").value;
    if(manv == ""){
        MSG(chefmsg);
    }
    else{
        var f = document.getElementById("frmcook");
        f.action = "../DauBep_Controller?action=PhanCongMA";
        f.submit();
        $.modal.close();
        if(id == null){
            id = setInterval( "Cook()", 2000 );
        }
    }
}
function HuyPhanCongMA(){
    $.modal.close();
    if(id == null){
        id = setInterval( "Cook()", 2000 );
    }
}

// End đầu bếp

// Start hóa đơn

function Bill(item, rightmsg) { // Show trang nhật ký
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../HoaDon_Controller?action=Show&item="+item;
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function CheckAllHD(){
    x = document.dshd.total.value;
    if(x > 1){
        optionHD = document.dshd.optionHD;
        for(i=0; i<optionHD.length; i++)
        {
            if(!optionHD[i].checked){
                optionHD[i].click();
            }
        }
    }
    else{
        $('.optionHD').click();
    }
}
function DeleteHD(item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=60";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var x = "";
                totall = document.dshd.total.value;
                if(totall > 1){
                    optionHD = document.dshd.optionHD;
                    for(i = 0; i < optionHD.length; i++)
                    {
                        if(optionHD[i].checked)
                        {
                            x =   x  + optionHD[i].value + "-" ;
                        }
                    }
                }
                else{
                    if(document.dshd.optionHD.checked){
                        x = document.dshd.optionHD.value;
                    }
                }
                if(x == "") return;
                else{
                    var a = "../HoaDon_Controller?action=DeleteHD&sohd="+x+"&item="+item;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortNgayGioHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ngaygio";
                if(sort == 'down'){
                    $('#titledskv1 div.down1').removeClass('down1');
                    $('#titledskv1 #sortkv1').addClass('up1');
                    var order1 = "asc";
                    var a = "../HoaDon_Controller?action=SortNgayGio&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv1 div.up1').removeClass('up1');
                    $('#titledskv1 #sortkv1').addClass('down1');
                    var order2 = "desc";
                    var aa = "../HoaDon_Controller?action=SortNgayGio&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSoHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "hd";
                if(sort == 'down'){
                    $('#titledskv2 div.down1').removeClass('down1');
                    $('#titledskv2 #sortkv2').addClass('up1');
                    var order1 = "asc";
                    var a = "../HoaDon_Controller?action=SortSoHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv2 div.up1').removeClass('up1');
                    $('#titledskv2 #sortkv2').addClass('down1');
                    var order2 = "desc";
                    var aa = "../HoaDon_Controller?action=SortSoHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortKhuVucHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "khuvuc";
                if(sort == 'down'){
                    $('#titledskv3 div.down1').removeClass('down1');
                    $('#titledskv3 #sortkv3').addClass('up1');
                    var order1 = "asc";
                    var a = "../HoaDon_Controller?action=SortKhuVucHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv3 div.up1').removeClass('up1');
                    $('#titledskv3 #sortkv3').addClass('down1');
                    var order2 = "desc";
                    var aa = "../HoaDon_Controller?action=SortKhuVucHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortBanHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "ban";
                if(sort == 'down'){
                    $('#titledskv4 div.down1').removeClass('down1');
                    $('#titledskv4 #sortkv4').addClass('up1');
                    var order1 = "asc";
                    var a = "../HoaDon_Controller?action=SortBanHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv4 div.up1').removeClass('up1');
                    $('#titledskv4 #sortkv4').addClass('down1');
                    var order2 = "desc";
                    var aa = "../HoaDon_Controller?action=SortBanHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortTongCongHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var sortkv = "tc";
                if(sort == 'down'){
                    $('#titledskv5 div.down1').removeClass('down1');
                    $('#titledskv5 #sortkv5').addClass('up1');
                    var order1 = "asc";
                    var a = "../HoaDon_Controller?action=SortTongCongHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:a,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
                if(sort == 'up'){
                    $('#titledskv5 div.up1').removeClass('up1');
                    $('#titledskv5 #sortkv5').addClass('down1');
                    var order2 = "desc";
                    var aa = "../HoaDon_Controller?action=SortTongCongHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv;
                    $.ajax({
                        url:aa,
                        dataType:"html",
                        success:function(result){
                            $("#DSHD").html(result);
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SearchHD(item, rightmsg, msgdate){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchHD .tungay').val();
                var tugio = $('#searchHD .tugio').val();
                var tuphut = $('#searchHD .tuphut').val();
                var denngay = $('#searchHD .denngay').val();
                var dengio = $('#searchHD .dengio').val();
                var denphut = $('#searchHD .denphut').val();
                var hoadon = $('#searchHD .hoadon').val();
                var khuvuc = $('#searchHD .khuvuc').val();
                var ban = $('#searchHD .ban').val();
                var tongcong = $('#searchHD .tongcong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var a = "../HoaDon_Controller?action=Search&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong+"&item="+item;
                                $.ajax({
                                    url:a,
                                    dataType:"html",
                                    success:function(result){
                                        $("#DSHD").html(result);
                                    }
                                });
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }

            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchNgayGioHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchHD .tungay').val();
                var tugio = $('#searchHD .tugio').val();
                var tuphut = $('#searchHD .tuphut').val();
                var denngay = $('#searchHD .denngay').val();
                var dengio = $('#searchHD .dengio').val();
                var denphut = $('#searchHD .denphut').val();
                var hoadon = $('#searchHD .hoadon').val();
                var khuvuc = $('#searchHD .khuvuc').val();
                var ban = $('#searchHD .ban').val();
                var tongcong = $('#searchHD .tongcong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "ngaygio";
                                if(sort == 'down'){
                                    $('#titledskv1 div.down1').removeClass('down1');
                                    $('#titledskv1 #sortkv1').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../HoaDon_Controller?action=SortSearchNgayGio&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv1 div.up1').removeClass('up1');
                                    $('#titledskv1 #sortkv1').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../HoaDon_Controller?action=SortSearchNgayGio&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
  
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchSoHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchHD .tungay').val();
                var tugio = $('#searchHD .tugio').val();
                var tuphut = $('#searchHD .tuphut').val();
                var denngay = $('#searchHD .denngay').val();
                var dengio = $('#searchHD .dengio').val();
                var denphut = $('#searchHD .denphut').val();
                var hoadon = $('#searchHD .hoadon').val();
                var khuvuc = $('#searchHD .khuvuc').val();
                var ban = $('#searchHD .ban').val();
                var tongcong = $('#searchHD .tongcong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "hd";
                                if(sort == 'down'){
                                    $('#titledskv2 div.down1').removeClass('down1');
                                    $('#titledskv2 #sortkv2').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../HoaDon_Controller?action=SortSearchSoHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv2 div.up1').removeClass('up1');
                                    $('#titledskv2 #sortkv2').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../HoaDon_Controller?action=SortSearchSoHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchKhuVucHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchHD .tungay').val();
                var tugio = $('#searchHD .tugio').val();
                var tuphut = $('#searchHD .tuphut').val();
                var denngay = $('#searchHD .denngay').val();
                var dengio = $('#searchHD .dengio').val();
                var denphut = $('#searchHD .denphut').val();
                var hoadon = $('#searchHD .hoadon').val();
                var khuvuc = $('#searchHD .khuvuc').val();
                var ban = $('#searchHD .ban').val();
                var tongcong = $('#searchHD .tongcong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "khuvuc";
                                if(sort == 'down'){
                                    $('#titledskv3 div.down1').removeClass('down1');
                                    $('#titledskv3 #sortkv3').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../HoaDon_Controller?action=SortSearchKhuVucHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv3 div.up1').removeClass('up1');
                                    $('#titledskv3 #sortkv3').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../HoaDon_Controller?action=SortSearchKhuVucHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchBanHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchHD .tungay').val();
                var tugio = $('#searchHD .tugio').val();
                var tuphut = $('#searchHD .tuphut').val();
                var denngay = $('#searchHD .denngay').val();
                var dengio = $('#searchHD .dengio').val();
                var denphut = $('#searchHD .denphut').val();
                var hoadon = $('#searchHD .hoadon').val();
                var khuvuc = $('#searchHD .khuvuc').val();
                var ban = $('#searchHD .ban').val();
                var tongcong = $('#searchHD .tongcong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "ban";
                                if(sort == 'down'){
                                    $('#titledskv4 div.down1').removeClass('down1');
                                    $('#titledskv4 #sortkv4').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../HoaDon_Controller?action=SortSearchBanHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv4 div.up1').removeClass('up1');
                                    $('#titledskv4 #sortkv4').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../HoaDon_Controller?action=SortSearchBanHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function SortSearchTongCongHD( sort, item, rightmsg){
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=59";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var tungay = $('#searchHD .tungay').val();
                var tugio = $('#searchHD .tugio').val();
                var tuphut = $('#searchHD .tuphut').val();
                var denngay = $('#searchHD .denngay').val();
                var dengio = $('#searchHD .dengio').val();
                var denphut = $('#searchHD .denphut').val();
                var hoadon = $('#searchHD .hoadon').val();
                var khuvuc = $('#searchHD .khuvuc').val();
                var ban = $('#searchHD .ban').val();
                var tongcong = $('#searchHD .tongcong').val();
                if(tungay != "" && denngay == ""){
                    MSG(msgdate);
                }
                else if(tungay == "" && denngay != ""){
                    MSG(msgdate);
                }
                else if(tugio == "" || tuphut == "" || dengio == "" || denphut == ""){
                    MSG(msgdate);
                }
                else{
                    var x = "../NhatKyHT_Controller?action=CheckDate&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut;
                    $.ajax({
                        url:x,
                        dataType:"html",
                        success:function(result){
                            if(result == "true"){
                                var sortkv = "tc";
                                if(sort == 'down'){
                                    $('#titledskv5 div.down1').removeClass('down1');
                                    $('#titledskv5 #sortkv5').addClass('up1');
                                    var order1 = "asc";
                                    var a = "../HoaDon_Controller?action=SortSearchTongCongHD&item="+item+"&order="+order1+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:a,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                                if(sort == 'up'){
                                    $('#titledskv5 div.up1').removeClass('up1');
                                    $('#titledskv5 #sortkv5').addClass('down1');
                                    var order2 = "desc";
                                    var aa = "../HoaDon_Controller?action=SortSearchTongCongHD&item="+item+"&order="+order2+"&sort="+sort+"&sortkv="+sortkv+"&tungay="+tungay+"&tugio="+tugio+"&tuphut="+tuphut+"&denngay="+denngay+"&dengio="+dengio+"&denphut="+denphut+"&hoadon="+hoadon+"&khuvuc="+khuvuc+"&ban="+ban+"&tongcong="+tongcong;
                                    $.ajax({
                                        url:aa,
                                        dataType:"html",
                                        success:function(result){
                                            $("#DSHD").html(result);
                                        }
                                    });
                                }
                            }
                            else{
                                MSG(msgdate);
                            }
                        }
                    });
                }
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
// End hóa đơn

function Company(rightmsg) { 
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=62";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var a = "../DoanhNghiep_Controller?action=Show";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function UpdateCompany(rightmsg, msgupdate) { 
    var b = "../NhanVien_Controller?action=CheckQuyenCaNhan&maquyen=63";
    $.ajax({
        url:b,
        dataType:"html",
        success:function(result){
            if(result == "yes"){
                var name = $('#company .name').val();
                var address = $('#company .address').val();
                var phonenumber = $('#company .phonenumber').val();
                var a = "../DoanhNghiep_Controller?action=UpdateCompany&name="+name+"&address="+address+"&phonenumber="+phonenumber+"";
                $.ajax({
                    url:a,
                    dataType:"html",
                    success:function(result){
                        MSG(msgupdate);
                        $("#content").html(result);
                    }
                });
            }
            else{
                MSG(rightmsg);
            }
        }
    });
}
function ShowChangePass(){ 
    $('#changepass:visible').slideUp('medium');
    if($('#changepass').is(':hidden')==true){
        $('#changepass').slideDown('medium');
        
    }    
}
function Changepass(passmsg, msgchecksubmit, detailusermsg){
    var tennv = $('#changepass .tennv').val();
    var newpass = $('#changepass .newpass').val();
    var diachi = $('#changepass .diachi').val();
    var sodt = $('#changepass .sodt').val();
    if( tennv == "" || diachi == "" || sodt == "" ){
        MSG(msgchecksubmit);
    }
    else if(newpass != "" && newpass.length < 5 ){
        MSG(passmsg);
    }
    else{
        var f = document.getElementById("changepasss");
        f.action = "../NhanVien_Controller?action=Changepass";
        f.method = "POST";
        f.submit();
    }
}
function Changepass1(passmsg, msgchecksubmit, detailusermsg){
    var tennv = $('#changepass .tennv').val();
    var newpass = $('#changepass .newpass').val();
    var diachi = $('#changepass .diachi').val();
    var sodt = $('#changepass .sodt').val();
    if( tennv == "" || diachi == "" || sodt == "" ){
        MSG(msgchecksubmit);
    }
    else if(newpass != "" && newpass.length < 5 ){
        MSG(passmsg);
    }
    else{
        var f = document.getElementById("changepasss");
        f.action = "NhanVien_Controller?action=Changepass";
        f.method = "POST";
        f.submit();
    }
}